Skip to content
Back to formatted view

Raw Message

Message-ID: <2ad0cc110902252004tf39ff1j361698ecf2ef3e60@mail.gmail.com>
Date: 2009-02-26T04:04:19Z
From: Kingsford Jones
Subject: variance on random effects in the lme() function
In-Reply-To: <E757FBF5-AD03-42FF-BB4E-F1D1F9829AC3@gmail.com>

You can use VarCorr to extract the values, but (oddly enough) it
returns values as character so you need to use 'as.numeric.  Here's an
example:

library(nlme)
f1 <- lme(distance ~ age, data = Orthodont, random = ~1 + age|Subject)
summary(f1)
VarCorr(f1) # prints the values of interest:

# Subject = pdSymm(age)
#             Variance   StdDev    Corr
# (Intercept) 5.41508686 2.3270339 (Intr)
# age         0.05126947 0.2264276 -0.609
# Residual    1.71620459 1.3100399

# note returned values are character:

str(VarCorr(f1))

# 'VarCorr.lme' chr [1:3, 1:3] "5.41508686" "0.05126947" "1.71620459"
"2.3270339" ...
# - attr(*, "dimnames")=List of 2
# ..$ : chr [1:3] "(Intercept)" "age" "Residual"
#  ..$ : chr [1:3] "Variance" "StdDev" "Corr"
# - attr(*, "title")= chr "Subject = pdSymm(age)"

# thus to extract the estimated variance of the subject intercepts:

as.numeric(VarCorr(f1))[1]
# [1] 5.415087

And you can ignore the warning about NA values


hth,

Kingsford Jones