Standard Error of variance component from the output of lmer

若如初见. 提交于 2019-11-30 18:24:55

问题


I need to extract the standard error of variance component from the output of lmer .

library(lme4)
model <- lmer(Reaction ~ Days + (1|Subject), sleepstudy)

The following produces estimates of variance component :

s2 <- VarCorr(model)$Subject[1]

It is NOT the standard error of the variance. And I want the standard error . How can I have it ?

EDIT :

Perhaps I am unable to make you understand what I meant by "standard error of the variance component". So I am editing my post .

In Chapter 12 , Experiments with Random Factors , of the book Design and Analysis of Experiments , by Douglas C. Montgomery , at the end of the chapter , Example 12-2 is done by SAS . In Example 12-2 , the model is a two-factor factorial random effect model .The output is given in Table 12-17

I am trying to fit the model in R by lmer .

library(lme4)
fit <- lmer(y~(1|operator)+(1|part),data=dat)

R codes for extracting the Estimate , annotated by 4 in the table 12-17 :

est_ope=VarCorr(fit)$operator[1]
est_part = VarCorr(fit)$part[1]
sig = summary(fit)$sigma
est_res = sig^2

Now I want to extract the results of Std Errors , annotated by 5 in the table 12-17 from lmer output .

Many Thanks !


回答1:


I think you are looking for the Wald standard error of the variance estimates. Please note that these (as often pointed out by Doug Bates) the Wald standard errors are often very poor estimates of the uncertainty of variances, because the likelihood profiles are often far from quadratic on the variance scale ... I'm assuming you know what you're doing and have some good use for these numbers ...

library("lme4")
model <- lmer(Reaction ~ Days + (1|Subject), sleepstudy, REML=FALSE)

(At present it's quite a bit harder to do this for the REML estimates ...)

Extract deviance function parameterized in terms of standard deviation and correlation rather than in terms of Cholesky factors (note this an internal function, so there's not a guarantee that it will keep working in the same way in the future ...)

 dd.ML <- lme4:::devfun2(model,useSc=TRUE,signames=FALSE)

Extract parameters as standard deviations on original scale:

 vv <- as.data.frame(VarCorr(model)) ## need ML estimates!
 pars <- vv[,"sdcor"]
 ## will need to be careful about order if using this for
 ## a random-slopes model ...

Now compute the second-derivative (Hessian) matrix:

library("numDeriv")
hh1 <- hessian(dd.ML,pars)
vv2 <- 2*solve(hh1)  ## 2* converts from log-likelihood to deviance scale
sqrt(diag(vv2))  ## get standard errors

These are the standard errors of the standard deviations: double them to get the standard errors of the variances (when you transform a value, its standard errors scale according to the derivative of the transformation).

I think this should do it, but you might want to double-check it ...




回答2:


I'm not really sure what you mean by "standard error of variance component". My best guess (based on your code) is that you want the standard error of the random effect. You can get this using package arm:

library(arm)
se.ranef(model)
#$Subject
#    (Intercept)
#308    9.475668
#309    9.475668
#310    9.475668
#330    9.475668
#331    9.475668
#332    9.475668
#333    9.475668
#334    9.475668
#335    9.475668
#337    9.475668
#349    9.475668
#350    9.475668
#351    9.475668
#352    9.475668
#369    9.475668
#370    9.475668
#371    9.475668
#372    9.475668

This is actually the square root of the conditional variance-covariance matrix of the random effect:

sqrt(attr(ranef(model, condVar = TRUE)$Subject, "postVar"))


来源:https://stackoverflow.com/questions/31694812/standard-error-of-variance-component-from-the-output-of-lmer

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!