Skip to content

variance on random effects in the lme() function

2 messages · bessie green, Kingsford Jones

#
Hello.

  I have a question about the lme() function in R.  I am trying to  
write a function so that I can do a power analysis for a linear mixed  
effects model I fit using the lme() function.  My trouble is that I  
can't figure out how to extract the variance on the random effects  
from the lme model (the one that is the intercept for StdDev under  
random effects in the summary output).  Can you tell me how I can call  
this piece of the output in a new function?

thank you,
Bessie Markley


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Bessie Green Markley
M.S. Candidate, Dept. of Biology and Wildlife
Alaska Cooperative Fish and Wildlife Research Unit
Institute of Arctic Biology
Sheenjek trailer, N. Koyukuk Drive
University of Alaska Fairbanks 99775
907-474-1949
#
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