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
fm1$call$fixed
# distance ~ age
fm1$call$random
# ~age | Subject
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With