# Brms formula for partially nested random effects

**URL:** <https://discourse.mc-stan.org/t/brms-formula-for-partially-nested-random-effects/29576>\
**Category:** Modeling\
**Tags:** specification, brms\
**Created:** [November 23, 2022, 3:10pm UTC](https://discourse.mc-stan.org/t/brms-formula-for-partially-nested-random-effects/29576 "2022-11-23T15:10:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Erik\_Ringen](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/erik_ringen/32/2948_2.png) [@Erik\_Ringen](https://discourse.mc-stan.org/u/Erik_Ringen)\
**Post date:** [November 23, 2022, 3:10pm UTC](https://discourse.mc-stan.org/t/brms-formula-for-partially-nested-random-effects/29576/1 "2022-11-23T15:10:46Z")

</div>

I am trying to model random effects that are nested, but only for a subset of all observations. Essentially, I have observations from 5 species coming from 3 clades (see attached image). However, 2 of the clades only have one species in them. For the clade with multiple species, I want to partially pool at the clade and species level.

I would find this straightforward to implement directly Stan, but am a bit stumped on the brms syntax.

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/mc_stan/original/2X/d/dbec62a8b9332e96ed284b8946d365841017e34f.png)

---

<div class="post-metadata">

**Author:** ![Zwelithini\_Tunyiswa](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/zwelithini_tunyiswa/32/10437_2.png) [@Zwelithini\_Tunyiswa](https://discourse.mc-stan.org/u/Zwelithini_Tunyiswa)\
**Post date:** [November 29, 2022, 2:03am UTC](https://discourse.mc-stan.org/t/brms-formula-for-partially-nested-random-effects/29576/2 "2022-11-29T02:03:32Z")

</div>

Try:

y ~ 1 + (1|genus) + (1|genus:species) # explicit nesting

or

y ~ 1 + (1|genus/species) # implicit nesting

---

<div class="post-metadata">

**Author:** ![Erik\_Ringen](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/erik_ringen/32/2948_2.png) [@Erik\_Ringen](https://discourse.mc-stan.org/u/Erik_Ringen)\
**Post date:** [November 29, 2022, 12:11pm UTC](https://discourse.mc-stan.org/t/brms-formula-for-partially-nested-random-effects/29576/3 "2022-11-29T12:11:35Z")

</div>

These formulations will estimate parameters for Genus2:Species4 and Genus3:Species5, which are poorly identified given their redundancy with Genus2 and Genus3, and the high uncertainty in variance across Genus. I wanted to know if there’s a way to not estimate species random effects for Genus 2 and 3.

I think a practical solution would be to dummy-code “Genus 1 (0/1)” and then have random effects only for Species.
