Skip to content
Back to formatted view

Raw Message

Message-ID: <9c15a6240903231221k2474a52bsf30a1f5be57bafec@mail.gmail.com>
Date: 2009-03-23T19:21:58Z
From: Ben Domingue
Subject: Extracting SD of random effects from lme object
In-Reply-To: <2ad0cc110903231218i6224878fk6c5f47751ab0cd85@mail.gmail.com>

On Mon, Mar 23, 2009 at 1:18 PM, Kingsford Jones
<kingsfordjones at gmail.com> wrote:
> 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,
>
That's what I needed.  Thanks.


Ben


> 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.
>>
>