[R] Extracting SD of random effects from lme object

Kingsford Jones kingsfordjones at gmail.com
Mon Mar 23 20:18:41 CET 2009


On Mon, Mar 23, 2009 at 11:26 AM, Ben Domingue <ben.domingue at gmail.com> wrote:
> Hello,
> How do I get the standard deviations for the random effects out of the
> lme object?  I feel like there's probably a simple way of doing this,
> but I can't see it.  Using the first example from the documentation:
>
>> fm1 <- lme(distance ~ age, data = Orthodont) # random is ~ age
>> fm1
> Linear mixed-effects model fit by REML
>  Data: Orthodont
>  Log-restricted-likelihood: -221.3183
>  Fixed: distance ~ age
> (Intercept)         age
>  16.7611111   0.6601852
>
> Random effects:
>  Formula: ~age | Subject
>  Structure: General positive-definite
>            StdDev    Corr
> (Intercept) 2.3270339 (Intr)
> age         0.2264276 -0.609
> Residual    1.3100399
>
> Number of Observations: 108
> Number of Groups: 27
>
> I want to extract the column vector (2.3270339, 0.2264276,
> 1.3100399)'.  Any thoughts?

To get the covariance matrix of the random effects:

> getVarCov(fm1)
Random effects variance covariance matrix
            (Intercept)       age
(Intercept)     5.41510 -0.321060
age            -0.32106  0.051269
  Standard Deviations: 2.327 0.22643


One way to extract the standard deviations shown by the print method above is:

> diag(sqrt(getVarCov(fm1)))
(Intercept)         age
  2.3270339   0.2264276
Warning message:
In sqrt(getVarCov(fm1)) : NaNs produced


And to get the estimate of the error standard deviation:

> fm1$sigma
[1] 1.31004


hth,

Kingsford Jones

> 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-help mailing list