Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extract random formula from nlme objects

I'm trying to extract the random structure from models constructed using lme, but I can't seem to get anything other than the fixed formula. E.g.,

library(nlme)
fm1 <- lme(distance ~ age, Orthodont, random = ~ age | Subject)
deparse(terms(fm1))
# "distance ~ age"

This is possible for lmer using findbars():

library(lmerTest)
fm2 <- lmer(Reaction ~ Days + (Days | Subject), sleepstudy)
findbars(formula(fm2))
# [[1]]
# Days | Subject

I want to be able to extract:

# ~ age | Subject
# (Days | Subject)

I could potentially get at this using regexpr but I would also like this to apply to more complex structures (multiple random slopes, nested random variables, etc.), and that might include additive or random slopes. Thanks!

like image 547
jslefche Avatar asked Nov 13 '14 15:11

jslefche


1 Answers

You can access these by

fm1$call$fixed
# distance ~ age
fm1$call$random
# ~age | Subject
like image 166
konvas Avatar answered Oct 23 '22 11:10

konvas