Articles

Affichage des articles du novembre, 2020

Generate a pseudo-Hessian matrix from MCMC series

The Hessian matrix at a point P (P is a vector) is the matrix of partial derivatives at this point. It is often used after non-linear optimization and the standard error of parameters can be obtained using the square-root of the diagonal of the inverse of the Hessian matrix. But when you are estimate SE like this, you lost the covariances between parameters. Then if you estimate random numbers using the SE of parameters, the original structure is lost. It is much better to estimate random numbers directly from the Hessian matrix. Then you keep the variance-covariance structure. When the model is fitted using MCMC, no Hessian matrix is directly available. A pseudo-Hessian matrix can be calculated using: hessian <- solve(cov( [matrix of values for different iterations] )) Let do an example with the fit of a normal distribution: First using maximum likelihood: val <- rnorm(30, 10, 2) library(MASS) ft <- fitdistr(val, densfun="normal") The Hessian matrix is not available

Confidence interval to check for difference: Use 1.96 SE and not 1.96 SD !

Let create two variables of length 100, one with mean 10 (A) and one with mean 12 (B) both with SD=2. Of course the two variables overlap. A <- rnorm(100, 10, 2) B <- rnorm(100, 12, 2) library(HelpersMG) barplot_errbar(c(mean(A) ,mean(B)), errbar.y = c(1.96*sd(A), 1.96*sd(B)), las=1, ylim=c(0, 20), main="1.96 x SD") Now do a t test. It is highly significant: t.test(A, B) Welch Two Sample t-test data:  A and B t = -7.8344, df = 197.93, p-value = 2.82e-13 alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval:  -2.737632 -1.636588 sample estimates: mean of x mean of y   9.741912 11.929021  Then if you want use the overall of confidence interval, use SE: barplot_errbar(c(mean(A) ,mean(B)), errbar.y = c(1.96*sd(A)/sqrt(length(A)),   1.96*sd(B)/sqrt(length(A))), las=1, ylim=c(0, 12), main="1.96 x SE")