我正在从这里学习混合效果模型。
我建立了一个简化模型并尝试提取来自线性混合效应模型的向量
然后计算方差. (这是一个玩具模型,我们对截距只有随机影响,所以是向量而不是矩阵)
为什么它不等于模型summary?(模型摘要显示 DID 截距方差为,但方差为是)。我在这里缺少什么?
> library(lme4)
> dat <-read.csv("http://stats.idre.ucla.edu/stat/data/hdp.csv")
> dat=dat[1:100,c("Age","Sex", "DID","mobility")]
> m <- lmer(mobility ~ 1 + Age + Sex +  (1 | DID), data = dat)
> summary(m)
Linear mixed model fit by REML ['lmerMod']
Formula: mobility ~ 1 + Age + Sex + (1 | DID)
   Data: dat
REML criterion at convergence: 228.5
Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-3.3152 -0.4710 -0.0252  0.9330  1.7854 
Random effects:
 Groups   Name        Variance Std.Dev.
 DID      (Intercept) 1.1480   1.0714  
 Residual             0.4532   0.6732  
Number of obs: 100, groups:  DID, 5
Fixed effects:
            Estimate Std. Error t value
(Intercept)  3.28826    0.76484   4.299
Age          0.01235    0.01178   1.048
Sexmale     -0.09126    0.14836  -0.615
Correlation of Fixed Effects:
        (Intr) Age   
Age     -0.766       
Sexmale -0.097  0.030
> var(as.numeric(getME(m, "b")))
[1] 1.102682