Reputation: 4599
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!
Upvotes: 5
Views: 548
Reputation: 14346
You can access these by
fm1$call$fixed
# distance ~ age
fm1$call$random
# ~age | Subject
Upvotes: 6