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?
Days
is continuous vs. categorical. If it's continuous then the models are not really comparable, because fit2 treats it as categorical. But imagineDays
were categorical. Then the main point is that fit2 is a restricted version of fit1. If you add (1|Days) to the model, then it's fit1 restricted to "compound symmetry". Whether you want to use a full model or a restricted model, depends primarily on the amount of data you have. $\endgroup$