# \[ANN\] Metida.jl: mixed-effects models fitting package

**URL:** https://discourse.julialang.org/t/ann-metida-jl-mixed-effects-models-fitting-package/54723
**Category:** Package Announcements
**Tags:** package, announcement, statistics
**Created:** [February 6, 2021, 8:58am UTC](https://discourse.julialang.org/t/ann-metida-jl-mixed-effects-models-fitting-package/54723 "2021-02-06T08:58:04Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![PharmCat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pharmcat/32/6953_2.png) [@PharmCat](https://discourse.julialang.org/u/PharmCat)
#### Post date: [February 6, 2021, 8:58am UTC](https://discourse.julialang.org/t/ann-metida-jl-mixed-effects-models-fitting-package/54723/1 "2021-02-06T08:58:04Z")

</div>

[Metida.jl](https://github.com/PharmCat/Metida.jl) is a Julia package for fitting mixed-effects models with flexible covariance structure.

Implemented covariance structures:

- Scaled Identity (SI)
- Diagonal (DIAG)
- Autoregressive (AR)
- Heterogeneous Autoregressive (ARH)
- Compound Symmetry (CS)
- Heterogeneous Compound Symmetry (CSH)
- Autoregressive Moving Average (ARMA)

All structures can be applied to the random (G) or repeated (R) part of the variance-covariance matrix (V). Where:

`V = ZGZ' + R`

Documentation available [here](https://pharmcat.github.io/Metida.jl/dev/).

v0.2.3

- Documentation
- FullDummyCoding fix
- FunctionTerm fix

---

<div class="post-metadata">

### Author: ![PharmCat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pharmcat/32/6953_2.png) [@PharmCat](https://discourse.julialang.org/u/PharmCat)
#### Post date: [February 16, 2021, 9:24pm UTC](https://discourse.julialang.org/t/ann-metida-jl-mixed-effects-models-fitting-package/54723/2 "2021-02-16T21:24:53Z")

</div>

Version 0.3.0 released.

Now random/repeated model syntax is near classic R/MixedModel style:

```julia
    lmm = LMM(@formula(var~sequence+period+formulation), df0;
    random = VarEffect(@covstr(formulation|subject), CSH),
    repeated = VarEffect(@covstr(formulation|subject), DIAG),
    )
    fit!(lmm)

```

No more subject keyword: now blocking factor construct automatically. Other minor things and documentation…

---

<div class="post-metadata">

### Author: ![PharmCat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pharmcat/32/6953_2.png) [@PharmCat](https://discourse.julialang.org/u/PharmCat)
#### Post date: [February 18, 2021, 5:49pm UTC](https://discourse.julialang.org/t/ann-metida-jl-mixed-effects-models-fitting-package/54723/3 "2021-02-18T17:49:30Z")

</div>

Version 0.4.0 released.

New covariance types:

- Toeplitz
- ToeplitzParameterized
- CustomCovarianceType

I think `CustomCovarianceType` is a really interesting thing. Users can specify methods to construct covariance matrix, G and R parts separately. [Read more in docs](https://pharmcat.github.io/Metida.jl/dev/instanduse/#Custom-structure)…

---

<div class="post-metadata">

### Author: ![PharmCat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pharmcat/32/6953_2.png) [@PharmCat](https://discourse.julialang.org/u/PharmCat)
#### Post date: [March 4, 2021, 4:32pm UTC](https://discourse.julialang.org/t/ann-metida-jl-mixed-effects-models-fitting-package/54723/4 "2021-03-04T16:32:43Z")

</div>

Version 0.6.0 released.

New covariance types:

- HeterogeneousToeplitz
- HeterogeneousToeplitzParameterized

Some changes in API, rho-link function, validation & documentation.

---

<div class="post-metadata">

### Author: ![Juan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juan/32/7657_2.png) [@Juan](https://discourse.julialang.org/u/Juan)
#### Post date: [March 4, 2021, 6:41pm UTC](https://discourse.julialang.org/t/ann-metida-jl-mixed-effects-models-fitting-package/54723/5 "2021-03-04T18:41:31Z")

</div>

Hello.

How does it compare to the MixedModels.jl package in terms of memory usage, speed and capabilities?

---

<div class="post-metadata">

### Author: ![PharmCat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pharmcat/32/6953_2.png) [@PharmCat](https://discourse.julialang.org/u/PharmCat)
#### Post date: [March 4, 2021, 7:09pm UTC](https://discourse.julialang.org/t/ann-metida-jl-mixed-effects-models-fitting-package/54723/6 "2021-03-04T19:09:21Z")

</div>

Hello! `MixedModels.jl` much faster, and consume less memory. If Mixed Models.jl applicable for your task it will be better to use `MixedModels.jl` If you need Satterthwaite ddf approximation, analysis with repeated measurements, or application of some nontrivial covariance structures - `Metida.jl` solve these problems. I didn’t found `MixedEffects.jl` maybe you mean `MixedModels.jl`, anyway if I missed this package, please guide me to it.

---

<div class="post-metadata">

### Author: ![PharmCat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pharmcat/32/6953_2.png) [@PharmCat](https://discourse.julialang.org/u/PharmCat)
#### Post date: [March 21, 2021, 7:40pm UTC](https://discourse.julialang.org/t/ann-metida-jl-mixed-effects-models-fitting-package/54723/8 "2021-03-21T19:40:35Z")

</div>

Version 0.7.1 released.

Better performance (twice faster in some tasks), dof\_satter method for a multidimensional case, minor changes, a bugfix for LMM show, documentation, more stable tests.

---

<div class="post-metadata">

### Author: ![PharmCat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pharmcat/32/6953_2.png) [@PharmCat](https://discourse.julialang.org/u/PharmCat)
#### Post date: [May 4, 2021, 4:08pm UTC](https://discourse.julialang.org/t/ann-metida-jl-mixed-effects-models-fitting-package/54723/9 "2021-05-04T16:08:08Z")

</div>

Version 0.9.1 released.

- documentation fix
- add test
- add experimental Type III Tests of Fixed Effects

MetidaNLopt, MetidaCu updated for v0.9.0.

---

<div class="post-metadata">

### Author: ![PharmCat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pharmcat/32/6953_2.png) [@PharmCat](https://discourse.julialang.org/u/PharmCat)
#### Post date: [November 4, 2021, 1:05pm UTC](https://discourse.julialang.org/t/ann-metida-jl-mixed-effects-models-fitting-package/54723/10 "2021-11-04T13:05:58Z")

</div>

Version 0.12.0 released.

The custom covariance structure was redesigned. Now it can be easily implemented, just add one struct and 2-3 methods. Doc [here](https://pharmcat.github.io/Metida.jl/stable/custom/). Better performance with multithreading. Minor changes in output.

---

<div class="post-metadata">

### Author: ![PharmCat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pharmcat/32/6953_2.png) [@PharmCat](https://discourse.julialang.org/u/PharmCat)
#### Post date: [December 13, 2021, 12:02pm UTC](https://discourse.julialang.org/t/ann-metida-jl-mixed-effects-models-fitting-package/54723/11 "2021-12-13T12:02:57Z")

</div>

[Metida](https://github.com/PharmCat/Metida.jl) Version 0.12.2 will be released soon.

List of implemented covariance structures:

- Scaled Identity (SI)
- Diagonal (DIAG)
- Autoregressive (AR)
- Heterogeneous Autoregressive (ARH)
- Compound Symmetry (CS)
- Heterogeneous Compound Symmetry (CSH)
- Autoregressive Moving Average (ARMA)
- Toeplitz (TOEP)
- Toeplitz Parameterized (TOEPP)
- Heterogeneous Toeplitz (TOEPH)
- Heterogeneous Toeplitz Parameterized (TOEPHP)
- Spatial Exponential (SPEXP)
- Spatial Power (SPPOW)
- Spatial Gaussian (SPGAU)
- Custom Covariance Type

Now, ‘rand’ is available for generating a random response vector from the fitted model ([docs](https://pharmcat.github.io/Metida.jl/dev/api/#Base.rand)).

---

<div class="post-metadata">

### Author: ![PharmCat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pharmcat/32/6953_2.png) [@PharmCat](https://discourse.julialang.org/u/PharmCat)
#### Post date: [December 31, 2021, 2:23pm UTC](https://discourse.julialang.org/t/ann-metida-jl-mixed-effects-models-fitting-package/54723/12 "2021-12-31T14:23:19Z")

</div>

Metida Version 0.12.4 released.

Better performance;  
Better ‘rand’ and ‘rand!’ implementation;  
Estimates table for all coefficients.

Made some preparations for parametric bootstrap and multiple imputations.

Happy New Year! 😸 ☃ 🎉 🎆

---

<div class="post-metadata">

### Author: ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)
#### Post date: [January 2, 2022, 9:27pm UTC](https://discourse.julialang.org/t/ann-metida-jl-mixed-effects-models-fitting-package/54723/13 "2022-01-02T21:27:02Z")

</div>

Out of curiosity, why there are hard-coded limitations, e.g. 160k observations? Doesn’t depend from the hardware?

---

<div class="post-metadata">

### Author: ![PharmCat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pharmcat/32/6953_2.png) [@PharmCat](https://discourse.julialang.org/u/PharmCat)
#### Post date: [January 3, 2022, 12:17am UTC](https://discourse.julialang.org/t/ann-metida-jl-mixed-effects-models-fitting-package/54723/14 "2022-01-03T00:17:53Z")

</div>

Hi! I think this is not ‘hard-coded limitations’. 😸 When the model is constructed full Z matrix is used for this. This means that if you have 200k observations and 50k subjects - Z matrix will be 200x50k (10 000 mln numbers) and this matrix will be out of memory. I think this problem can be solved in some cases. So in StatsModels there is no easy way to get a sparse model matrix for categorical terms with many levels.

---

<div class="post-metadata">

### Author: ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)
#### Post date: [January 3, 2022, 6:34am UTC](https://discourse.julialang.org/t/ann-metida-jl-mixed-effects-models-fitting-package/54723/15 "2022-01-03T06:34:22Z")

</div>

Ok, so there isn’t any hard coded limits… I think how it is written now isn’t too clear… ir really seems like the one stated are fixed problem limite, like in some commercial software… .  
You could write instead something like “a standard pc with xxx GB of RAM can efficiently process problems up to …”

---

<div class="post-metadata">

### Author: ![PharmCat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pharmcat/32/6953_2.png) [@PharmCat](https://discourse.julialang.org/u/PharmCat)
#### Post date: [January 3, 2022, 11:55am UTC](https://discourse.julialang.org/t/ann-metida-jl-mixed-effects-models-fitting-package/54723/16 "2022-01-03T11:55:59Z")

</div>

I think I should add some clarification in docs. Also in some cases, it is very difficult to predict how many observations can be handled, because, for example, if the model includes two random factors by 100k levels it will cost twice memory as one. So it is not only a data-dependent problem. The solution is to make a sparse Z matrix, for this own implementation of StatsModels methods should be done - and this is part of work on future.

---

<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: [January 14, 2022, 6:14pm UTC](https://discourse.julialang.org/t/ann-metida-jl-mixed-effects-models-fitting-package/54723/17 "2022-01-14T18:14:33Z")

</div>

@sylvaticus If you don’t need structured R-side covariance, then MixedModels.jl already uses optimized sparse methods for Z matrices. We don’t have support for many restricted G-side (random effects) covariance structures out of the box but they’re not too hard to implement. The “DIAG” case here corresponds to `zerocorr` in MixedModel; the “SI” case here could be implemented without too much difficulty. One of my TODOs is to document how to create new types for restricted G-side covariance.

---

<div class="post-metadata">

### Author: ![PharmCat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pharmcat/32/6953_2.png) [@PharmCat](https://discourse.julialang.org/u/PharmCat)
#### Post date: [August 2, 2022, 3:14pm UTC](https://discourse.julialang.org/t/ann-metida-jl-mixed-effects-models-fitting-package/54723/18 "2022-08-02T15:14:09Z")

</div>

Metida Version 0.14.0 released.

New features:

- [@lmmformula](https://pharmcat.github.io/Metida.jl/dev/api/#Metida.@lmmformula) macro for better syntax

Use

```julia
lmm = LMM(@lmmformula(response ~ 1 + factor,
    random = 1|subject/r1,
    repeated = p|subject:CSH),
    ftdf3)

```

instead:

```julia
lmm = LMM(@formula(response ~ 1 + factor), ftdf3;
    random = [VarEffect(@covstr(1|subject), SI),
    VarEffect(@covstr(1|r1&subject), SI)],
    repeated = VarEffect(@covstr(p|subject), CSH))

```

- New covariance structure - [Unstructured](https://pharmcat.github.io/Metida.jl/dev/api/#Metida.Unstructured)

Also preparation for REML analytical gradient estimation, minor changes and docs.

---

<div class="post-metadata">

### Author: ![PharmCat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pharmcat/32/6953_2.png) [@PharmCat](https://discourse.julialang.org/u/PharmCat)
#### Post date: [December 28, 2022, 4:38pm UTC](https://discourse.julialang.org/t/ann-metida-jl-mixed-effects-models-fitting-package/54723/19 "2022-12-28T16:38:25Z")

</div>

Metida Version 0.14.3 released.

New features:

- `raneff` function returns random-effect coefficients vector.

Minor optimizations and changes in internal structure.

Analytical gradient code included (but no improving performance).

---

<div class="post-metadata">

### Author: ![PharmCat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pharmcat/32/6953_2.png) [@PharmCat](https://discourse.julialang.org/u/PharmCat)
#### Post date: [January 19, 2024, 2:33pm UTC](https://discourse.julialang.org/t/ann-metida-jl-mixed-effects-models-fitting-package/54723/20 "2024-01-19T14:33:12Z")

</div>

Metida Version 0.15.0 will be released soon.

Upcoming features:

- weights
- multiple repeated effects

Now it available in dev brunch, but soon will be merged in master brunch.

---

<div class="post-metadata">

### Author: ![PharmCat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pharmcat/32/6953_2.png) [@PharmCat](https://discourse.julialang.org/u/PharmCat)
#### Post date: [August 29, 2024, 11:58pm UTC](https://discourse.julialang.org/t/ann-metida-jl-mixed-effects-models-fitting-package/54723/21 "2024-08-29T23:58:50Z")

</div>

Metida 0.16.0 released.

- “matrix weights”
- custom structures remake - add block id attribute to `rmat!` functions
- add one post processing step to change covariance type object if necessary
- “raw columns” factor coding - now possible work with tuples or any structures for spatial fitting and other
- ScaledWeightedCov - structure for R matrix - user provided covariance matrix scaled by `σ^2`
- minor optimizations

[Next page](https://discourse.julialang.org/t/ann-metida-jl-mixed-effects-models-fitting-package/54723.md?page=2)
