# Nested random effects in MixedModels

**URL:** https://discourse.julialang.org/t/nested-random-effects-in-mixedmodels/40290
**Category:** Statistics
**Tags:** question, package
**Created:** [May 27, 2020, 8:40pm UTC](https://discourse.julialang.org/t/nested-random-effects-in-mixedmodels/40290 "2020-05-27T20:40:02Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![talat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/talat/32/12970_2.png) [@talat](https://discourse.julialang.org/u/talat)
#### Post date: [May 27, 2020, 8:40pm UTC](https://discourse.julialang.org/t/nested-random-effects-in-mixedmodels/40290/1 "2020-05-27T20:40:02Z")

</div>

What is the correct specification of nested random effects in julia’s MixedModels package?

What I’m trying to model can be done in R using lme4:

```julia
y ~ x + (1 | site / block)

```

so that blocks are nested in sites. How would this nesting be specified in a GeneralizedLinearMixedModel of MixedModels package?

---

<div class="post-metadata">

### Author: ![dave.f.kleinschmidt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dave.f.kleinschmidt/32/55_2.png) [@dave.f.kleinschmidt](https://discourse.julialang.org/u/dave.f.kleinschmidt)
#### Post date: [June 30, 2020, 3:50pm UTC](https://discourse.julialang.org/t/nested-random-effects-in-mixedmodels/40290/2 "2020-06-30T15:50:40Z")

</div>

I think that should work (at least if you’re on the latest dev branch, which you can get by doing `] add MixedModels#master`. (I’m not sure if that feature was released yet or not…it looks like 2.3.0 was release after the PR supporting that syntax was merged, [https://github.com/JuliaStats/MixedModels.jl/pull/197](https://github.com/JuliaStats/MixedModels.jl/pull/197))

Also, note that that’s equivalent to `(1 | site) + (1 | site & block)`, although support for interactions in ranef grouping expressions was also merged in the same PR.
