# GeneralizedLinearMixedModel no method matching \_ranef\_refs

**URL:** <https://discourse.julialang.org/t/generalizedlinearmixedmodel-no-method-matching-ranef-refs/82859>\
**Category:** Statistics\
**Created:** [June 16, 2022, 7:20am UTC](https://discourse.julialang.org/t/generalizedlinearmixedmodel-no-method-matching-ranef-refs/82859 "2022-06-16T07:20:33Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)\
**Post date:** [June 16, 2022, 7:20am UTC](https://discourse.julialang.org/t/generalizedlinearmixedmodel-no-method-matching-ranef-refs/82859/1 "2022-06-16T07:20:33Z")

</div>

How can I fix this error?

```julia
form = @formula(y ~ (1 | a * b * c))
n = 1000
df = DataFrame(
    y=rand(Bool, n), 
    a=CategoricalArray(rand('a':'z', n)), 
    b=CategoricalArray(rand('a':'z', n)), 
    c=CategoricalArray(rand('a':'z', n)), 
)
@time fit(GeneralizedLinearMixedModel, form, df, MixedModels.Bernoulli())

julia> @time fit(GeneralizedLinearMixedModel, form, df, MixedModels.Bernoulli())
ERROR: MethodError: no method matching _ranef_refs(::Tuple{StatsModels.CategoricalTerm{DummyCoding, Char, 25}, StatsModels.CategoricalTerm{DummyCoding, Char, 25}, StatsModels.CategoricalTerm{DummyCoding, Char, 25}, StatsModels.InteractionTerm{Tuple{StatsModels.CategoricalTerm{DummyCoding, Char, 25}, StatsModels.CategoricalTerm{DummyCoding, Char, 25}}}, StatsModels.InteractionTerm{Tuple{StatsModels.CategoricalTerm{DummyCoding, Char, 25}, StatsModels.CategoricalTerm{DummyCoding, Char, 25}}}, StatsModels.InteractionTerm{Tuple{StatsModels.CategoricalTerm{DummyCoding, Char, 25}, StatsModels.CategoricalTerm{DummyCoding, Char, 25}}}, StatsModels.InteractionTerm{Tuple{StatsModels.CategoricalTerm{DummyCoding, Char, 25}, StatsModels.CategoricalTerm{DummyCoding, Char, 25}, StatsModels.CategoricalTerm{DummyCoding, Char, 25}}}}, ::NamedTuple{(:y, :a, :b, :c), Tuple{Vector{Bool}, CategoricalVector{Char, UInt32, Char, CategoricalValue{Char, UInt32}, Union{}}, CategoricalVector{Char, UInt32, Char, CategoricalValue{Char, UInt32}, Union{}}, CategoricalVector{Char, UInt32, Char, CategoricalValue{Char, UInt32}, Union{}}}})

```

---

<div class="post-metadata">

**Author:** ![palday](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palday/32/12640_2.png) [@palday](https://discourse.julialang.org/u/palday)\
**Post date:** [June 16, 2022, 4:05pm UTC](https://discourse.julialang.org/t/generalizedlinearmixedmodel-no-method-matching-ranef-refs/82859/2 "2022-06-16T16:05:03Z")

</div>

The problem is you have a grouping variable `a * b * c` that isn’t supported. This isn’t supported because I haven’t seen a case where it makes sense statistically. Can you give us more context on the underlying statistical or scientific question you’re trying to address with such a model?

---

<div class="post-metadata">

**Author:** ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)\
**Post date:** [June 16, 2022, 6:28pm UTC](https://discourse.julialang.org/t/generalizedlinearmixedmodel-no-method-matching-ranef-refs/82859/3 "2022-06-16T18:28:17Z")

</div>

I have a bunch of observations from different groups in different locations and years. Each observation is (id, group, location, year, value). I wanted to estimate the average `value` in each (group, location, year). The sample size in each (group, location, year) varies, with some being small.

I wanted to get more realistic estimates for the small-size tuples by sharing information with the large ones. For example, (group 1, location 1, year 1) is small so its average value has high variance, but it could be pulled toward the middle by (group 1, location 1, year y), (group 1, location ℓ, year 1), and (group g, location 1, year 1).

Does that seem like a sensible goal? Is there a better way of going about it?

---

<div class="post-metadata">

**Author:** ![palday](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palday/32/12640_2.png) [@palday](https://discourse.julialang.org/u/palday)\
**Post date:** [June 16, 2022, 6:57pm UTC](https://discourse.julialang.org/t/generalizedlinearmixedmodel-no-method-matching-ranef-refs/82859/4 "2022-06-16T18:57:57Z")

</div>

So you want a random intercept for each combination of group, location and year? Then you need `a & b & c` not `a * b * c`. The problem with `(1|a * b * c)` is that it expands to `(1|a) + (1|b) + (1|c) + (1|a&b) + (1|a&c) + (1|b&c) + (1|a&b&c)` which in most cases won’t be identifiable.

That hopefully addresses the computational question, but I’m not sure if that’s the ideal way to answer the inferential question – I haven’t had time to think about it deeply and I would probably need more information to give more specific advice.

---

<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 23, 2022, 3:07pm UTC](https://discourse.julialang.org/t/generalizedlinearmixedmodel-no-method-matching-ranef-refs/82859/5 "2022-06-23T15:07:20Z")

</div>

@jar1 does `(1 | a & b & c)` give you what you want? That’s what we use for things like the nesting syntax (e.g., `(1 | a / b)` lowers to `(1 | a) + (1 | a & b)` IIRC…that might be backwards)

---

<div class="post-metadata">

**Author:** ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)\
**Post date:** [June 26, 2022, 5:44pm UTC](https://discourse.julialang.org/t/generalizedlinearmixedmodel-no-method-matching-ranef-refs/82859/6 "2022-06-26T17:44:53Z")

</div>

Yes, I think that’s working for me. Thank you both.

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [July 12, 2022, 8:19pm UTC](https://discourse.julialang.org/t/generalizedlinearmixedmodel-no-method-matching-ranef-refs/82859/7 "2022-07-12T20:19:58Z")

</div>

A post was split to a new topic: [How to estimate uncertainty in a LinearMixedModel?](https://discourse.julialang.org/t/how-to-estimate-uncertainty-in-a-linearmixedmodel/84124)
