I am learning generalized linear mixed effects model, and today I realized that there are two ways to set random slope in
lmer(), when dealing with data where same subjects are repeatedly measured.
fit1 <- lmer(Reaction ~ Days + (Days | Subject), sleepstudy) fit2 <- lmer(Reaction ~ Days + (1|Days:Subject), sleepstudy)
Looking at the results, it seems like
lmer() doing different things. How each command differs from each other, and which should I use and when?
Update: Thanks to Matteo Lisi's answer and to the earlier post Difference between (factor|group) and (1|factor:group) specifications in lme4, I now understand the mechanism that the
lme4 package is doing. However, I am still having difficulty understanding WHEN should I use WHICH. I would appreciate if you could explain for what types of research designs I should use which syntax.
- Is that something I can choose based on AIC? Or, I should choose the syntax based on the design of the research?
- Could you provide examples of research designs?