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.9165  8135.8330  8153.8330  8153.8568  8216.2372

Variance components:
        Column   VarianceStd.Dev.
subj (Intercept)  1.79300 1.33903
item (Intercept)  0.11717 0.34230

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

Fixed-effects parameters:
──────────────────────────────────────────────────────
                   Coef.  Std. Error       z  Pr(>|z|)
──────────────────────────────────────────────────────
(Intercept)   -0.15753     0.38519     -0.41    0.6826
anger          0.0575689   0.0167508    3.44    0.0006
gender: M      0.320278    0.191184     1.68    0.0939
btype: scold  -1.05901     0.184172    -5.75    <1e-08
btype: shout  -2.10387     0.186531   -11.28    <1e-28
situ: self    -1.05398     0.151205    -6.97    <1e-11
mode: want     0.707707    0.151019     4.69    <1e-05
──────────────────────────────────────────────────────

Contents