'Standard Error of variance component from the output of lmer
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 !
Solution 1:[1]
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"))
Solution 2:[2]
mn2=lmer(pun~ pre + (pre|pro), REML = TRUE, data = pro)
summary(mn2)
coe2=coef(mn2)
coe2
# Matriz de varianza-covarianza (covarianza)
as.data.frame(VarCorr(mn2))
# Extraer coeficientes fijos
fixef(mn2)
# Extraer desvios de a - alfa y b - beta
re=as.data.frame(ranef(mn2))
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Roland |
| Solution 2 | Adrian Mole |

