Does coef() work for nested varying effects?

I recently discovered coef() in brms. Now, I think I may have discovered that I have been misinterpreting random effects for nested models.

Let’s say I have this model:
outcome ~ 1 + treat + (1 + treat|Region/District/School)

If I wanted the slope of the effect of treatment on a specific School (say School A, in District B, in Region C), then I thought I would extract the posterior samples and do:
(population level effect of treat) + (random effect of treat for Region C) + (random effect of treat for District B) + (random effect of treat for School A)

In other words, I thought all of these random effects were offsets from both the population-level effect and the Group level within which they were nested. Is that not correct??

When I call coef() it appears to simply add the population-level effect for treat to the random effect of treat for School A, without including the effects of Region or District that the School is in.

@paul.buerkner have I completely misunderstood nested random effects or coef() ?


Coef() will indeed nor consider nesting of random effects. Instead you have to use ranef() and add the random effects manually as you indicated.

1 Like

Awesome. Thanks for the clarification!
I’ll just use ranef(model, summary=FALSE) and add them myself.
It’s relieving that I wasn’t mistaken about random effects in nested models.

Thanks for the quick response, clarification, and super awesome brms package!