Need help with MixedModels.jl?
Click the โ€œchatโ€ button below for chat support from the developer who created it, or find similar developers for support.

About the developer

295 Stars 44 Forks MIT License 1.0K Commits 24 Opened issues


A Julia package for fitting (statistical) mixed-effects models

Services available


Need anything else?

Contributors list

Mixed-effects models in Julia

|Documentation|Citation|Build Status|Code Coverage| |:-:|:-:|:-:|:-:| |Stable Docs Dev Docs | DOI | Tier 1 Tier 2 PkgEval | CodeCov |

This package defines linear mixed models (

) and generalized linear mixed models (
). Users can use the abstraction for statistical model API to build, fit (
), and query the fitted models.

A mixed-effects model is a statistical model for a response variable as a function of one or more covariates. For a categorical covariate the coefficients associated with the levels of the covariate are sometimes called effects, as in "the effect of using Treatment 1 versus the placebo". If the potential levels of the covariate are fixed and reproducible, e.g. the levels for

could be
, they are modeled with fixed-effects parameters. If the levels constitute a sample from a population, e.g. the
or the
at a particular observation, they are modeled as random effects.

A mixed-effects model contains both fixed-effects and random-effects terms.

With fixed-effects it is the coefficients themselves or combinations of coefficients that are of interest. For random effects it is the variability of the effects over the population that is of interest.

In this package random effects are modeled as independent samples from a multivariate Gaussian distribution of the form ๐“‘ ~ ๐“(0, ๐šบ). For the response vector, ๐ฒ, only the mean of conditional distribution, ๐“จ|๐“‘ = ๐› depends on ๐› and it does so through a linear predictor expression, ๐›ˆ = ๐—๐›ƒ + ๐™๐›, where ๐›ƒ is the fixed-effects coefficient vector and ๐— and ๐™ are model matrices of the appropriate sizes,

In a

the conditional mean, ๐› = ๐”ผ[๐“จ|๐“‘ = ๐›], is the linear predictor, ๐›ˆ, and the conditional distribution is multivariate Gaussian, (๐“จ|๐“‘ = ๐›) ~ ๐“(๐›, ฯƒยฒ๐ˆ).

In a

, the conditional mean, ๐”ผ[๐“จ|๐“‘ = ๐›], is related to the linear predictor via a link function. Typical distribution forms are Bernoulli for binary data or Poisson for count data.

Currently Supported Platforms

|OS|OS Version|Arch|Julia|Tier| |:-:|:-:|:-:|:-:|:-:| |Linux|Ubuntu 18.04|x64|v1.6|1| |macOS|Catalina 10.15|x64|v1.6|1| |Windows|Server 2019|x64|v1.6|1|

Note that previous releases still support older Julia versions.

Version 4.0.0

Version 4.0.0 contains some user-visible changes and many changes in the underlying code.

Please see NEWS for a complete overview, but a few key points are:

  • The internal storage of the model matrices in
    has changed and been optimized. This change should be transparent to users who are not manipulating the fields of the model
  • The handling of rank deficiency continues to evolve.
  • Additional
    methods have been added for generalizing to new data.
  • saveoptsum
    provide for saving and restoring the
    and thus offer a way to serialize a model fit.
  • There is improved support for the runtime construction of model formula, especially
    s and nested terms (methods for
    Base.|(::AbstractTerm, ::AbstractTerm)
    Base./(::AbstractTerm, ::AbstractTerm)
  • A progress display is shown by default for models taking more than a few hundred milliseconds to fit. This can be disabled with the keyword argument

Quick Start

julia> using MixedModels

julia> m1 = fit(MixedModel, @formula(yield ~ 1 + (1|batch)), MixedModels.dataset(:dyestuff)) Linear mixed model fit by maximum likelihood yield ~ 1 + (1 | batch) logLik -2 logLik AIC AICc BIC -163.6635 327.3271 333.3271 334.2501 337.5307

Variance components: Column Variance Std.Dev. batch (Intercept) 1388.3332 37.2603 Residual 2451.2501 49.5101 Number of obs: 30; levels of grouping factors: 6

Fixed-effects parameters: โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Coef. Std. Error z Pr(>|z|) โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ (Intercept) 1527.5 17.6946 86.33 <1e-99 โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

julia> using Random

julia> bs = parametricbootstrap(MersenneTwister(42), 1000, m1); Progress: 100%%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ| Time: 0:00:00

julia> propertynames(bs) 13-element Vector{Symbol}: :allpars :objective :ฯƒ :ฮฒ :se :coefpvalues :ฮธ :ฯƒs :ฮป :inds :lowerbd :fits :fcnames

julia> bs.coefpvalues # returns a row table 1000-element Vector{NamedTuple{(:iter, :coefname, :ฮฒ, :se, :z, :p), Tuple{Int64, Symbol, Float64, Float64, Float64, Float64}}}: (iter = 1, coefname = Symbol("(Intercept)"), ฮฒ = 1517.0670832927115, se = 20.76271142094811, z = 73.0669059804057, p = 0.0) (iter = 2, coefname = Symbol("(Intercept)"), ฮฒ = 1503.5781855888436, se = 8.1387737362628, z = 184.7425956676446, p = 0.0) (iter = 3, coefname = Symbol("(Intercept)"), ฮฒ = 1529.2236379016574, se = 16.523824785737837, z = 92.54659001356465, p = 0.0) โ‹ฎ (iter = 998, coefname = Symbol("(Intercept)"), ฮฒ = 1498.3795009457242, se = 25.649682012258104, z = 58.417079019913054, p = 0.0) (iter = 999, coefname = Symbol("(Intercept)"), ฮฒ = 1526.1076747922416, se = 16.22412120273579, z = 94.06411945042063, p = 0.0) (iter = 1000, coefname = Symbol("(Intercept)"), ฮฒ = 1557.7546433870125, se = 12.557577103806015, z = 124.04898098653763, p = 0.0)

julia> using DataFrames

julia> DataFrame(bs.coefpvalues) # puts it into a DataFrame 1000ร—6 DataFrame โ”‚ Row โ”‚ iter โ”‚ coefname โ”‚ ฮฒ โ”‚ se โ”‚ z โ”‚ p โ”‚ โ”‚ โ”‚ Int64 โ”‚ Symbol โ”‚ Float64 โ”‚ Float64 โ”‚ Float64 โ”‚ Float64 โ”‚ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”‚ 1 โ”‚ 1 โ”‚ (Intercept) โ”‚ 1517.07 โ”‚ 20.7627 โ”‚ 73.0669 โ”‚ 0.0 โ”‚ โ”‚ 2 โ”‚ 2 โ”‚ (Intercept) โ”‚ 1503.58 โ”‚ 8.13877 โ”‚ 184.743 โ”‚ 0.0 โ”‚ โ”‚ 3 โ”‚ 3 โ”‚ (Intercept) โ”‚ 1529.22 โ”‚ 16.5238 โ”‚ 92.5466 โ”‚ 0.0 โ”‚ โ‹ฎ โ”‚ 998 โ”‚ 998 โ”‚ (Intercept) โ”‚ 1498.38 โ”‚ 25.6497 โ”‚ 58.4171 โ”‚ 0.0 โ”‚ โ”‚ 999 โ”‚ 999 โ”‚ (Intercept) โ”‚ 1526.11 โ”‚ 16.2241 โ”‚ 94.0641 โ”‚ 0.0 โ”‚ โ”‚ 1000 โ”‚ 1000 โ”‚ (Intercept) โ”‚ 1557.75 โ”‚ 12.5576 โ”‚ 124.049 โ”‚ 0.0 โ”‚

julia> DataFrame(bs.ฮฒ) 1000ร—3 DataFrame โ”‚ Row โ”‚ iter โ”‚ coefname โ”‚ ฮฒ โ”‚ โ”‚ โ”‚ Int64 โ”‚ Symbol โ”‚ Float64 โ”‚ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”‚ 1 โ”‚ 1 โ”‚ (Intercept) โ”‚ 1517.07 โ”‚ โ”‚ 2 โ”‚ 2 โ”‚ (Intercept) โ”‚ 1503.58 โ”‚ โ”‚ 3 โ”‚ 3 โ”‚ (Intercept) โ”‚ 1529.22 โ”‚ โ‹ฎ โ”‚ 998 โ”‚ 998 โ”‚ (Intercept) โ”‚ 1498.38 โ”‚ โ”‚ 999 โ”‚ 999 โ”‚ (Intercept) โ”‚ 1526.11 โ”‚ โ”‚ 1000 โ”‚ 1000 โ”‚ (Intercept) โ”‚ 1557.75 โ”‚

Funding Acknowledgement

The development of this package was supported by the Center for Interdisciplinary Research, Bielefeld (ZiF)/Cooperation Group "Statistical models for psychological and linguistic data".

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.