[R-sig-ME] [R] Extract Residual Variance from lmer using VarCorr

Douglas Bates bates at stat.wisc.edu
Tue Nov 4 21:21:03 CET 2008


It is important when discussing the behavior of lmer and other
functions in the lme4 package to state the version of the package that
you are using.  The package changes as I experiment with the
computational methods.

Using version 0.999375-27 of the lme4 package you can see the following

> fm1 <- lmer(Reaction ~ Days + (Days|Subject), sleepstudy)
> str(VarCorr(fm1))
List of 1
 $ Subject: num [1:2, 1:2] 612.1 9.6 9.6 35.1
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : chr [1:2] "(Intercept)" "Days"
  .. ..$ : chr [1:2] "(Intercept)" "Days"
  ..- attr(*, "stddev")= Named num [1:2] 24.74 5.92
  .. ..- attr(*, "names")= chr [1:2] "(Intercept)" "Days"
  ..- attr(*, "correlation")= num [1:2, 1:2] 1 0.0655 0.0655 1
  .. ..- attr(*, "dimnames")=List of 2
  .. .. ..$ : chr [1:2] "(Intercept)" "Days"
  .. .. ..$ : chr [1:2] "(Intercept)" "Days"
 - attr(*, "sc")= Named num 25.6
  ..- attr(*, "names")= chr "sigmaREML"

so the value that you want for the residual standard deviation is

attr(VarCorr(fm1), "sc")

An alternative is to examine

> fm1 at deviance
          ML         REML         ldL2        ldRX2      sigmaML    sigmaREML
1.751986e+03 1.743628e+03 7.595997e+01 8.276128e+00 2.544924e+01 2.559182e+01
       pwrss         disc         usqr         wrss          dev         llik
1.165795e+05 9.888088e+04 1.769928e+04 9.888024e+04           NA           NA
     NULLdev
          NA

and notice that there are two elements called "sigmaML" and "sigmaREML".

Both these methods are sub-optimal in that they rely on a particular
version of the fitted model object.  I wrote an extractor named
"sigma" to obtain the estimate of the standard deviation but did not
export it because I am not convinced that this is a good name for such
an extractor.  Suggestions for the name of an extractor (or comments
that I have missed the obvious generic function) and what it should
return are welcome.

I have cc:'d the R-SIG-Mixed-Models mailing list as it is the more
likely list for help on such questions.


On Tue, Nov 4, 2008 at 1:14 PM, Benjamin Michael Kelcey
<bkelcey at umich.edu> wrote:
>
> I am trying to extract the residual variance from an lmer object. I have
> tried using VarCorr() which allows me to see the estimate but can not save
> it by itself.
>
> How can I get this from VarCorr() or is there another function available for
> this?
> Thanks,
> ben
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>




More information about the R-sig-mixed-models mailing list