Extract random formula from nlme objects

I am trying to extract a random structure from models built with lme, but I cannot get anything but a fixed formula. For instance.

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

This is possible lmerwith 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 use this with help regexpr, but I would also like it to apply to more complex structures (multiple random slopes, nested random variables, etc.) and which may include additive or random slopes. Thank!

+4
source share
1 answer

You can access them using

fm1$call$fixed
# distance ~ age
fm1$call$random
# ~age | Subject
+5
source

All Articles