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!
You can access these by