0

I'm trying to extract the value of the Variance from a Random Effects model built in R, using the lme4 package:

Linear mixed model fit by REML ['lmerMod']
Formula: PH ~ (1 | gen) + rep
   Data: tab

REML criterion at convergence: 591.3

Scaled residuals: 
 Min       1Q   Median       3Q      Max 
-2.09030 -0.53055  0.04938  0.66689  2.02929 

Random effects:
Groups   Name        Variance Std.Dev.
 gen      (Intercept) 34.99    5.915   
 Residual             75.16    8.670   
Number of obs: 80, groups:  gen, 40

Fixed effects:
        Estimate Std. Error t value
(Intercept)  296.268      3.205   92.45
rep            8.550      1.939    4.41

Correlation of Fixed Effects:
(Intr)
rep -0.907

I'm interested in the Random effects section - the Variance for the "gen" Group (the value is 34.99). Can anyone help?

neuron
  • 269
  • 2
  • 11
  • You might find some useful information in my answer here: [How to compute the residual standard deviation from `glmer()` function in R?](http://stats.stackexchange.com/a/161676/7290) – gung - Reinstate Monica Nov 15 '15 at 17:19

1 Answers1

2

First you could the save random effect section in a data frame:

m1 <- lmer(Reaction ~ Days + (Days|Subject), sleepstudy)

out <- as.data.frame(VarCorr(m1))

Then have look at out:

> out
       grp        var1 var2       vcov       sdcor
1  Subject (Intercept) <NA> 612.089747 24.74044759
2  Subject        Days <NA>  35.071663  5.92213327
3  Subject (Intercept) Days   9.604334  0.06555133
4 Residual        <NA> <NA> 654.941041 25.59181589

And finally index the value you want, e.g.

> out[1,4]
[1] 612.0897
Stefan
  • 4,977
  • 1
  • 18
  • 38