TanyaMurphy
1/18/2017 - 2:01 PM

R code for multi-level models

R code for multi-level models

# From http://rpsychologist.com/r-guide-longitudinal-lme-lmer#three-level-models

# lme
lmer(y ~ time * tx + 
                (time | therapist/subjects), 
        data=df)
## expands to
lmer(y ~ time * tx + 
                (time | therapist:subjects) + 
                (time | therapist),
        data=df)

# nlme
lme(y ~ time * tx, 
         random = ~time | therapist/subjects, 
         data=df)

## expands to
lme(y ~ time * tx, 
         random = list(therapist = ~time, 
                        subjects = ~time), 
         data=df)