When fitting the following simple model, using the 'lme4' R package and including a fixed and random slope term, I get:
Linear mixed model fit by REML ['lmerMod']
Formula: s ~ -1 + v8 + ((0 + v8 | Test))
Data: d
Random effects:
Groups Name Variance Std.Dev.
Test v8 0.07676 0.2771
Residual 3.56656 1.8885
Number of obs: 1647, groups: Test, 41
Fixed effects:
Estimate Std. Error t value
v8 2.83955 0.07845 36.2
Accordingly to my understanding of the model, the random effects of the above model are assumed to be a sample from a normal distribution with zero mean and variance equal to 0.07676. However when computing the variance directly from the estimated random effects I get a different result:
> var(ranef(m)$Test[,1])
[1] 0.02310659
> ranef(m)$Test[, 1]
[1] -0.160035611 0.091979744 0.024448306 0.103303471 -0.209127498 -0.115072081 -0.100169758 -0.439242134 -0.099724601 0.025481345
[11] 0.029968465 -0.099253951 0.166403989 -0.219299028 0.223841767 0.153699949 0.264563114 -0.143304606 0.177523761 0.054762082
[21] -0.056088689 -0.079896085 -0.013745153 0.122520213 0.214254150 0.252858418 -0.082402046 -0.095554209 0.000000000 0.045516274
[31] -0.017687631 0.003380337 -0.034645355 -0.184548770 0.143998225 -0.178323836 0.144361920 -0.106175741 -0.030701297 0.000000000
[41] 0.222132549
I was expecting to see something close to 0.07676 rather than 0.02310659?Could anybody clarify why I'm seeing this discrepancy?
If I plot the results I get:
plot(density(ranef(m)$Test[,1]), col="green")
hist(ranef(m)$Test[,1], freq=F, add=T)
curve(dnorm(x,mean=0,sd=0.2771), -1,1, col='red', add=T)
curve(dnorm(x,mean=0,sd=sd(ranef(m)$Test[,1])), -1,1, col='blue',add=T)
Where the green curve is the random effects non parametric density estimate, the blue curve is a gaussian with the variance estimated directly from the random effects and the red curve is a gaussian with a variance equal to the one returned by the lmer model.