# Getting started with mixed models

**URL:** <https://discourse.julialang.org/t/getting-started-with-mixed-models/41998>\
**Category:** Data\
**Created:** [June 24, 2020, 4:39pm UTC](https://discourse.julialang.org/t/getting-started-with-mixed-models/41998 "2020-06-24T16:39:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [June 24, 2020, 4:39pm UTC](https://discourse.julialang.org/t/getting-started-with-mixed-models/41998/1 "2020-06-24T16:39:45Z")

</div>

I think I’m missing something very basic with `MixedModels`…

```julia
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?

---

<div class="post-metadata">

**Author:** ![dmbates](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dmbates/32/44_2.png) [@dmbates](https://discourse.julialang.org/u/dmbates)\
**Post date:** [June 24, 2020, 9:36pm UTC](https://discourse.julialang.org/t/getting-started-with-mixed-models/41998/2 "2020-06-24T21:36:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [June 24, 2020, 9:48pm UTC](https://discourse.julialang.org/t/getting-started-with-mixed-models/41998/3 "2020-06-24T21:48:14Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![dmbates](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dmbates/32/44_2.png) [@dmbates](https://discourse.julialang.org/u/dmbates)\
**Post date:** [June 24, 2020, 10:02pm UTC](https://discourse.julialang.org/t/getting-started-with-mixed-models/41998/4 "2020-06-24T22:02:55Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [June 24, 2020, 10:36pm UTC](https://discourse.julialang.org/t/getting-started-with-mixed-models/41998/5 "2020-06-24T22:36:18Z")

</div>

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