Stef
Stef

Reputation: 33

Specifying level-3 random intercept in R

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?

Upvotes: 3

Views: 1568

Answers (1)

Joe
Joe

Reputation: 8631

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.

Upvotes: 1

Related Questions