I feel slightly embarrassed to be asking this question but is it possible to specify a random effect for a predictor that is on the highest level of a multilevel model? I searched online but cannot find a clear answer. I have students (L1) nested in teachers (L2) and am looking at the effect of teaching practices (L2 variable) on some student-level outcome variables. Can these teaching practice effects be modelled as random or can only effects of student-level predictors be modelled as random? I tried the random effects with brms and the models all looked fine. Thanks!
Yes, instead of assuming a random effect of mean zero and estimated standard deviation, you can compute the mean as the result of an equation with covariates!
I am not sure you can implement this model in brms, though!
Thanks for responding! I basically just modelled a random slope for the predictor on the highest level in the same way I did as for variables on the lowest level…
So something like this:
Outcome ~ 0 + Intercept + student_predictor + classroom_predictor + (0 + Intercept + student_predictor + classroom_predictor |p| classroom)
And the model converged fine. Does that seem OK then?
I just got confused because I cannot seem to find any papers in which they modelled highest-level predictors as random effects. So I thought that this is maybe not a thing.
I think modeling the teaching practice effects as random should be no problem. In general, I don’t see a problem with random effects on different nested levels. There are some options, though:
- You have to pay attention to how you handle the lower levels (students in your example) programmatically. In lme4, there’s the nesting syntax
(1 | g1/g2)which is equivalent to
(1 | g1) + (1 | g1:g2)(see Table 2 here) but I don’t know if that nesting syntax is also supported by brms. With the nesting syntax, it’s possible to have the same student codes within each teacher (e.g.
stud2, …) even though
stud1of teacher 1 is not the same person as
stud1of teacher 2. To be safe, I think it’s better to have students coded like
teacher2_stud1, …). Then you also don’t need the nesting syntax.
- brms offers argument
gr()which leads to separate variance-covariance matrices for each level of the
byvariable. That might be interesting for you, too.
Note that I am assuming that each student has only one teacher since you said
I couldn’t really connect your formula
to your initial post so I can’t say anything about that.
Thank you. Sorry, I should have said teacher rather than classroom in the simplified example code. I actually have a cross-classified multiple membership structure, with students (L1) nested in classrooms (L2) and teachers (L2), whereby some students belonged to multiple classrooms and/or teachers over the course of the study. So much more complicated than this. But the important thing is that my main question has been a answered and I now know that it was not a mistake to model the effects on the highest level as random. Thanks so much!
Ok, that sounds rather like a multi-membership problem. See function
brms::mm() (perhaps also
brms::mmc()) for that. This vignette also partly deals with multi-membership models.