I'm trying to use the
lmer() function in R to specify a particular random effects structure for a model that has four levels: each measurement on a students occurs in one or more groups, and each group occurs in one of several districts.
The structure of the data is such that I have a combination of nested and crossed random effects:
- Groups are nested in districts
- Students are crossed with groups
- Students are nested in districts
- Students can contribute a data point to more than one group
In other words, a specific student can occur in more than one group within the same district (e.g. Student S2 in the graph below occurs in Group 1 and Group 2), but not in more than one district (Student S2 only ever occurs in District 1). A specific group occurs in only one district (e.g. Group 4 only ever occurs in District 2).
I know how to specify a 2-level model with crossed or nested effects. For instance, if I wanted to specify random intercepts:
In a 2-level model with crossed effects district and group, I would use
(1 | district) + (1 | group)
In a 2-level model with group nested within district, I would use
(1 | district/group)
But how do I specify the combination of crossed and nested effects outlined for my 4-level model above, and in the graph below? I'm not sure how to translate all the dependencies into the correct
lmer() model syntax.
UPDATE: I left out some important details about data at the student level:
- Within each group, there is one data point per student in that group
- 95% of the students are associated with only one group (that is, they contribute one data point to the analysis)
- 5% of the students are associated with more than one group (usually, with 2 groups and at most with 3 groups); they contribute multiple data points to the analysis
- Of those 5%, about half contribute the same measurement (that is, the same values for the predictors and dependent variable) as a data point in more than one group
- The other half of those 5% do not contribute the same measurement across different groups. That is, the same student contributes (partly) different values for the predictors and a different value for the dependent variable across groups