3

I am using the lmer() function (lme4 package) in R for analysing a longitudinal study in which I measured 120 subjects, 6 times. In first instance, I specified a model like this:

library(lme4)
model1 = lmer(DV ~ 1 + X1*X2  + (1+X1|SubjectID), REML="false")

X1 is a time-varying variable (level-1) and X2 is a subject-level variable (level-2).

Because these subjects are nested within several teams, I was advised to include a random intercept at the team-level (level-3). However, I only find how to include both random intercept and slope:

model2 = lmer(DV ~ 1 + X1*X2  + (1+X1|TeamID/SubjectID), REML="false")

Does anyone know how to add only a level-3 random intercept to model 1?

help-info.de
  • 6,695
  • 16
  • 39
  • 41
Stef
  • 33
  • 3
  • So is `X1` the timepoint? What's a "subject level variable"? Maybe you could give a sample of your data. – Joe Nov 12 '16 at 11:24
  • X1 is a level-1 variable that has a different value every wave/timepoint (there are 6 timepoints). In other words, its value changes over time. X2 is a level-2 variable, which has the same value during all waves. So, each subject has a value of X2 that remains constant over time. It is actually a very basic multi-level model I guess? Is this clear enough? @Joe – Stef Nov 14 '16 at 13:56
  • 1
    So it sounds like you are looking for random intercepts only for `TeamID` and `SubjectID`. If this is the case you only need `(1|TeamID) + (1|SubjectID)`. – Joe Nov 14 '16 at 14:45
  • Okay I think I got it than. Thanks! So when I want a random intercept and random slope for SubjectID but only a random intercept for TeamID it would be (1+X1|SubjectID) + (1|TeamID)? – Stef Nov 14 '16 at 15:37
  • Exactly. You're saying "expect differing baselines only for `TeamID` but differing baselines and different responses to `X1` for `SujectID`". Does that clear up the matter? – Joe Nov 14 '16 at 16:24
  • Yes, that is exactly what I wanted to know. Thanks a lot! – Stef Nov 14 '16 at 16:34
  • Great. I've added it more clearly as an answer. Would you be so kind as to accept? – Joe Nov 14 '16 at 16:49

1 Answers1

1

By using the term (1|SubjectID) you're telling the model to expect differing baselines only for different instances of SubjectID. To tell the model to expect different responses of this to the fixed effect X1, we use (1+X1|SubjectID). Therefore, you just need the terms

(1|TeamID) + (1+X1|SubjectID)

in your model.

By the way there's plenty of good information about this on Cross Validated.

Community
  • 1
  • 1
Joe
  • 8,073
  • 1
  • 52
  • 58