MixedModels.jl Documentation

MixedModels.jl is a Julia package providing capabilities for fitting and examining linear and generalized linear mixed-effect models. It is similar in scope to the lme4 package for R.

Quick Start

You can fit a model using a lmer-style model formula using @formula and a dataset. Here is a short example of how to fit a linear mixed-effects modeling using the dyestuff dataset:

using DataFrames, MixedModels, MixedModelsDatasets  # load packages
dyestuff = MixedModelsDatasets.dataset(:dyestuff);   # load dataset

lmod = lmm(@formula(yield ~ 1 + (1|batch)), dyestuff)   # fit the model!
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.2500 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
────────────────────────────────────────────────

For a generalized linear mixed-effect model, you have to specify a distribution for the response variable (and optionally a link function). A quick example of generalized linear model using the verbagg dataset:

using DataFrames, MixedModels               # load packages
verbagg = MixedModelsDatasets.dataset(:verbagg);    # load dataset

frm = @formula(r2 ~ 1 + anger + gender + btype + situ + mode + (1|subj) + (1|item));
bernmod = glmm(frm, verbagg, Bernoulli())   # fit the model!
Generalized Linear Mixed Model fit by maximum likelihood (nAGQ = 1)
  r2 ~ 1 + anger + gender + btype + situ + mode + (1 | subj) + (1 | item)
  Distribution: Bernoulli{Float64}
  Link: LogitLink()

   logLik    deviance     AIC       AICc        BIC    
 -4067.9164  8135.8329  8153.8329  8153.8566  8216.2370

Variance components:
        Column   Variance Std.Dev. 
subj (Intercept)  1.793474 1.339206
item (Intercept)  0.117143 0.342261

 Number of obs: 7584; levels of grouping factors: 316, 24

Fixed-effects parameters:
──────────────────────────────────────────────────────
                   Coef.  Std. Error       z  Pr(>|z|)
──────────────────────────────────────────────────────
(Intercept)   -0.152989    0.385219    -0.40    0.6913
anger          0.0573955   0.0167527    3.43    0.0006
gender: M      0.320755    0.191207     1.68    0.0934
btype: scold  -1.05986     0.184154    -5.76    <1e-08
btype: shout  -2.10394     0.186513   -11.28    <1e-28
situ: self    -1.05435     0.151191    -6.97    <1e-11
mode: want     0.707035    0.151004     4.68    <1e-05
──────────────────────────────────────────────────────

Contents