A blog about biostatistics using R by Professor Marc Girondot, University Paris Saclay.
Subjects can be wide, from ecology to molecular phylogeny or statistics or just tricks to make life easier in R.
Flush warnings() cache and convert warnings to error for debugging
An Hessian matrix is a square matrix of partial second order derivative. From the square-root of the inverse of the diagonal, it is possible to estimate the standard error of parameters. Let take an example: val=rnorm(100, mean=20, sd=5) # Return -ln L of values in val in Gaussian distribution with mean and sd in par fitnorm<-function(par, val) { -sum(dnorm(val, par["mean"], par["sd"], log = TRUE)) } # Initial values for search p<-c(mean=20, sd=5) # fit the model result <- optim(par=p, fn=fitnorm, val=val, method="BFGS", hessian=TRUE) # Inverse the hessian matrix to get SE for each parameters mathessian <- result$hessian inversemathessian <- solve(mathessian) res <- sqrt(diag(inversemathessian)) # results data.frame(Mean=result$par, SE=res) library(MASS) (r<-fitdistr(val, "normal")) It works well. However, the inverse of the matrix cannot be calculated if the second order derivative for some paramete...
Introduction Correlation iconography is a not very well known method to study multivariate data. It was developed long-time ago by Michel Lesty: Lesty M (1999) Une nouvelle approche dans le choix des régresseurs de la régression multiple en présence d'intéractions et de colinearités. La revue de Modulad 22:41-77 It is also well described in a French Wikipedia page: https://fr.wikipedia.org/wiki/Iconographie_des_corrélations After checking the possibilities of this method, I think that it deserves more attention. Let take the example of the wikipedia page: dta <- read.table(text=gsub(",", ".", "Élève Poids Âge Assiduité Note e1 52 12 12 5 e2 59 12,5 9 5 e3 55 13 15 9 e4 58 14,5 5 5 e5 66 15,5 11 13,5 e6 62 16 15 18 e7 63 17 12 18 e8 69 18 9 18"), header=TRUE) > dta Élève Poids Âge Assiduité Note 1 e1 52 12.0 12 5.0 2 e...
Due to a bug in dropterm() and addterm() in package MASS, it is impossible to use AICc with stepAIC() . Here is a solution. Enter these commands and now you can use: stepAIC(g0, criteria="AICc") or stepAIC(g0, criteria="BIC") For example: datax <- data.frame(y=rnorm(100), x1=rnorm(100), x2=rnorm(100), x3=rnorm(100), x4=rnorm(100)) g0 <- glm(y ~ x1+x2+x3+x4, data=datax) gx_AICc <- stepAIC(g0, criteria="AICc") gx_AIC <- stepAIC(g0, criteria="AIC") gx_AIC <- stepAIC(g0, criteria="BIC")
Commentaires
Enregistrer un commentaire