[R-sig-ME] Extracting variances from a mer object
Douglas Bates
bates at stat.wisc.edu
Wed Jul 7 23:16:27 CEST 2010
On Wed, Jul 7, 2010 at 4:13 PM, Douglas Bates <bates at stat.wisc.edu> wrote:
> On Wed, Jul 7, 2010 at 4:06 PM, Gang Chen <gangchen6 at gmail.com> wrote:
>> This is a simple question. When fitting a model with lmer, how can I
>> extract all the variances from the output object? For example, with
>> the following analysis, I just want to extract the column of Variance
>> under the Random effects table - those 3 variance numbers: 0.63756 for
>> Subj, 23.03698 for Scan, and 199.50496 for Residual. VarCorr(fm) only
>> gives me the first two. I couldn't find any slots for this purpose
>> from str(fm) either.
>
> ?VarCorr
Sorry, I answered too quickly. You had checked the result of VarCorr.
The residual variance is square of the "sc" attribute.
> fm1 <- lmer(Yield ~ 1 + (1|Batch), Dyestuff)
> str(VarCorr(fm1))
List of 1
$ Batch: num [1, 1] 1764
..- attr(*, "dimnames")=List of 2
.. ..$ : chr "(Intercept)"
.. ..$ : chr "(Intercept)"
..- attr(*, "stddev")= Named num 42
.. ..- attr(*, "names")= chr "(Intercept)"
..- attr(*, "correlation")= num [1, 1] 1
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : chr "(Intercept)"
.. .. ..$ : chr "(Intercept)"
- attr(*, "sc")= num 49.5
> fm1
Linear mixed model fit by REML
Formula: Yield ~ 1 + (1 | Batch)
Data: Dyestuff
AIC BIC logLik deviance REMLdev
325.7 329.9 -159.8 327.4 319.7
Random effects:
Groups Name Variance Std.Dev.
Batch (Intercept) 1764.0 42.001
Residual 2451.3 49.510
Number of obs: 30, groups: Batch, 6
Fixed effects:
Estimate Std. Error t value
(Intercept) 1527.50 19.38 78.81
>>> (fm<-lmer(Rep~(1|Subj)+(1|Scan), data=Model))
>> Linear mixed model fit by REML
>> Formula: Rep ~ (1 | Subj) + (1 | Scan)
>> Data: Model
>> AIC BIC logLik deviance REMLdev
>> 166.4 170.3 -79.18 163.2 158.4
>> Random effects:
>> Groups Name Variance Std.Dev.
>> Subj (Intercept) 0.63756 0.79847
>> Scan (Intercept) 23.03698 4.79969
>> Residual 199.50496 14.12462
>> Number of obs: 20, groups: Subj, 10; Scan, 2
>>
>> Fixed effects:
>> Estimate Std. Error t value
>> (Intercept) 27.603 4.642 5.946
>>
>> Thanks,
>> Gang
>>
>> _______________________________________________
>> R-sig-mixed-models at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
>>
>
More information about the R-sig-mixed-models
mailing list