# Method Error when using LinearMixedModel function

**URL:** <https://discourse.julialang.org/t/method-error-when-using-linearmixedmodel-function/88243>\
**Category:** Specific Domains\
**Tags:** statistics\
**Created:** [October 4, 2022, 5:12pm UTC](https://discourse.julialang.org/t/method-error-when-using-linearmixedmodel-function/88243 "2022-10-04T17:12:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![imantha](https://avatars.discourse-cdn.com/v4/letter/i/6a8cbe/32.png) [@imantha](https://discourse.julialang.org/u/imantha)\
**Post date:** [October 4, 2022, 5:12pm UTC](https://discourse.julialang.org/t/method-error-when-using-linearmixedmodel-function/88243/1 "2022-10-04T17:12:16Z")

</div>

Hi I am having trouble using the Mixed Model package as following the example doesnt seem to work. I get the following Method Error  
`ERROR: MethodError: no method matching LinearMixedModel(::Vector{Int64}, ::Matrix{Float64}, ::StatsModels.FormulaTerm{StatsModels.ContinuousTerm{Float64}, StatsModels.MatrixTerm{Tuple{StatsModels.InterceptTerm{true}, StatsModels.ContinuousTerm{Float64}, StatsModels.ContinuousTerm{Float64}, StatsModels.InteractionTerm{Tuple{StatsModels.ContinuousTerm{Float64}, StatsModels.ContinuousTerm{Float64}}}}}}, ::Vector{Any}, ::Nothing) Closest candidates are: LinearMixedModel(::AbstractArray, ::Tuple, ::StatsModels.FormulaTerm, ::Any, ::Any) at ~/.julia/packages/MixedModels/1FpDN/src/linearmixedmodel.jl:85 LinearMixedModel(::AbstractArray, ::Tuple, ::StatsModels.FormulaTerm, ::Any) at ~/.julia/packages/MixedModels/1FpDN/src/linearmixedmodel.jl:85 LinearMixedModel(::AbstractArray, ::MixedModels.FeTerm{T}, ::AbstractVector{<:MixedModels.AbstractReMat{T}}, ::StatsModels.FormulaTerm, ::Any) where T at ~/.julia/packages/MixedModels/1FpDN/src/linearmixedmodel.jl:139`

```julia
using CSV: read
using DataFrames: DataFrame 
using MixedAnova: anova
using MixedModels: LinearMixedModel, dataset, fit, @formula

df = read("data/SubsEnzYield.csv", DataFrame)

fm1 = fit(
    LinearMixedModel,
    @formula(Yield ~ Substrate + Enzyme + Substrate & Enzyme), 
    df
)

```

The method error states to pass a Vector and Matrix, however if I do so I am not sure how to construct the formula.  
Thanks

---

<div class="post-metadata">

**Author:** ![awasserman](https://avatars.discourse-cdn.com/v4/letter/a/9de0a6/32.png) [@awasserman](https://discourse.julialang.org/u/awasserman)\
**Post date:** [October 4, 2022, 7:32pm UTC](https://discourse.julialang.org/t/method-error-when-using-linearmixedmodel-function/88243/2 "2022-10-04T19:32:33Z")

</div>

That’s a confusing error message.

But looking at your formula, there’s no grouping term (the right hand side of the pipe `|` operator, as shown in the docs [here](https://juliastats.org/MixedModels.jl/stable/constructors/#The-@formula-language-in-Julia)).

Something like this should work with a linear model (e.g., from `GLM`).

```julia
using GLM
linear_model_fit = fit(
    LinearModel,
    @formula(Yield ~ Substrate + Enzyme + Substrate & Enzyme), 
    df
)

```

If you do want to use the “random effects” of a mixed model, you can use the grouping terms to specify which variables are used for grouping these effects, and then see if that works with MixedModels.

---

<div class="post-metadata">

**Author:** ![awasserman](https://avatars.discourse-cdn.com/v4/letter/a/9de0a6/32.png) [@awasserman](https://discourse.julialang.org/u/awasserman)\
**Post date:** [October 4, 2022, 7:35pm UTC](https://discourse.julialang.org/t/method-error-when-using-linearmixedmodel-function/88243/3 "2022-10-04T19:35:38Z")

</div>

Also, as a side note, in the formula language, you can substitute

`a * b`

for

`a + b + a & b`

---

<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:** [October 6, 2022, 3:03pm UTC](https://discourse.julialang.org/t/method-error-when-using-linearmixedmodel-function/88243/4 "2022-10-06T15:03:57Z")

</div>

To be fair, it’s a confusing error message because the software is being asked to do something outside its scope and so you get a method error when you hit the edge of that design scope.

But this particular mistake should yield a more informative error in the most recent release (4.7.3).
