Getting started with mixed models

I think I’m missing something very basic with MixedModels

julia> using MixedModels, StatsBase

julia> t = (y = rand(100), x = rand(100));

julia> fit(MixedModel, @formula(y ~ x), t)
ERROR: MethodError: no method matching getindex(::StatsModels.MatrixTerm{Tuple{StatsModels.InterceptTerm{true},StatsModels.ContinuousTerm{Float64}}}, ::Int64)

What am I doing wrong?

A mixed model is one with both fixed-effects parameters and random effects. In your example you only have fixed-effects. Random effects are specified in the formula by terms like (1|G) where G is a grouping factor (categorical covariate). There are several examples of such fits in the first section of the package documentation.

Please feel free to submit issues on the package documentation if the purpose and its use is unclear.

Ah, I didn’t fully understand. I was just starting from reg y x and hoping to build my way up. Does MixedModels not include vanilla OLS?

No MixedModels does not include OLS. Perhaps confusingly that is part of the GLM package.

I guess those of us who came to Julia from R think the organization makes sense because it mirrors the way things are set up in R. Maybe we are making too many assumptions about the worldview here.

2 Likes

I’m glad there isn’t duplicated work! Perhaps that can be clarified in the docs better, though. I can file and issue.

1 Like