Method Error when using LinearMixedModel function

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

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

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).

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

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.

1 Like

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

a * b

for

a + b + a & b

1 Like

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).

1 Like