Skip to content
Prev 565 / 7420 Next

variance on random effects in the lme() function

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