I'm trying to specify properly a cross level effect with lmer()
and lme()
functions.
I'm working with a modified sleepstudy
data version, where I added a level 2 variable: score
to each participant:
library(lme4)
data(sleepstudy)
score <- gl(n = 5, k = 10, length = 180)
sleepstudy$score <- as.numeric(score)
My goal is to find the right lme4::lmer()
(and a nlme::lme()
analogue) syntax that would replicate the following formula:
Level 1:
$Reaction = \\beta_0 + \\beta_1(Days)+ r$
Level 2:
$ \\beta_0= \\gamma_{00} + \\gamma_{01}(Score) + u_0$
$ \\beta_1= \\gamma_{10} + \\gamma_{11}(Score) + u_1$
EDIT: i'm not sure why math equation are not rendered properly, so here goes a img of how it should look like:
For some unknown reason I'm having a hard time translating normal equations to lme4/nlme
syntax.
PS. I would use a read (if there is any) where regression equations are translated to syntax. So far I didn't find any.
By trial and error I found the proper solution for the given example:
lmer(Reaction ~ score*Days + (Days|Subject), data = sleepstudy)
I can leave this Q/A as is or delete if that's considered best practice.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.