Skip to content

Instantly share code, notes, and snippets.

@TanyaMurphy
Created January 18, 2017 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TanyaMurphy/b1b85c68f6f01af429c84efd5115cd3e to your computer and use it in GitHub Desktop.
Save TanyaMurphy/b1b85c68f6f01af429c84efd5115cd3e to your computer and use it in GitHub Desktop.
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment