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.793397 1.339178
item (Intercept)  0.117135 0.342251

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

Fixed-effects parameters:
──────────────────────────────────────────────────────
                   Coef.  Std. Error       z  Pr(>|z|)
──────────────────────────────────────────────────────
(Intercept)   -0.153745    0.385211    -0.40    0.6898
anger          0.0574292   0.0167524    3.43    0.0006
gender: M      0.320535    0.191203     1.68    0.0937
btype: scold  -1.05969     0.184149    -5.75    <1e-08
btype: shout  -2.10385     0.186508   -11.28    <1e-28
situ: self    -1.05436     0.151187    -6.97    <1e-11
mode: want     0.707005    0.151        4.68    <1e-05
──────────────────────────────────────────────────────

Contents