Code
using DataFrames
using MixedModels
using MixedModelsDatasets: dataset
using SMLP2026: fit_or_restorePhillip Alday
Reinhold Kliegl
2026-08-23
This page is a lookup reference, not a lesson. Use it to:
Prerequisites: Analysis of the sleepstudy data.
Datasets used: sleepstudy (see the dataset catalog).
Here we introduce most of the commands available in the MixedModels.jl package for the immediate inspection and analysis of results returned in a fitted linear mixed-effect model. All the examples use the random-slopes model for the sleepstudy data, which is small enough that everything here runs in seconds.
| Initialization | |
| Initial parameter vector | [1.0, 0.0, 1.0] |
| Initial objective value | 1784.6423001241371 |
| Optimizer settings | |
| Optimizer | LN_NEWUOA |
| Backend | nlopt |
| ftol_rel | 1.0e-12 |
| ftol_abs | 1.0e-8 |
| xtol_rel | 0.0 |
| xtol_abs | [1.0e-10, 1.0e-10, 1.0e-10] |
| initial_step | [1.0, 1.0, 1.0] |
| maxfeval | -1 |
| maxtime | -1.0 |
| xtol_zero_abs | 0.001 |
| ftol_zero_abs | 1.0e-5 |
| pirls_maxiter | 10 |
| pirls_ftol_rel | 1.4901161193847656e-8 |
| pirls_ftol_abs | 1.0e-5 |
| pirls_maxhalfstep | 10 |
| Result | |
| Function evaluations | 82 |
| Final parameter vector | [0.9292, 0.0182, 0.2226] |
| Final objective value | 1751.9393 |
| Return code | FTOL_REACHED |
1751.9393469156716
1751.9393469156716
| Coef. | Std. Error | z | Pr(>|z|) | |
|---|---|---|---|---|
| (Intercept) | 251.405 | 6.63228 | 37.91 | <1e-99 |
| days | 10.4673 | 1.50224 | 6.97 | <1e-11 |
2-element Vector{Float64}:
251.4051060532072
10.46728550560944
2-element Vector{Float64}:
251.4051060532072
10.46728550560944
2×2 Matrix{Float64}:
43.9871 -1.3705
-1.3705 2.25672
2×2 Matrix{Float64}:
1.0 -0.137555
-0.137555 1.0
2-element Vector{Float64}:
6.632279012514935
1.5022367701697787
(:formula, :reterms, :Xymat, :feterm, :sqrtwts, :parmap, :dims, :A, :L, :optsum, :θ, :theta, :β, :beta, :βs, :betas, :λ, :lambda, :stderror, :σ, :sigma, :σs, :sigmas, :σρs, :sigmarhos, :b, :u, :X, :y, :corr, :vcov, :PCA, :rePCA, :objective, :pvalues)
These commands inform us about the model parameters associated with the random-effects structure (RES).
| Column | Variance | Std.Dev | Corr. | |
|---|---|---|---|---|
| subj | (Intercept) | 565.51589 | 23.78058 | |
| days | 32.68220 | 5.71683 | +0.08 | |
| Residual | 654.94103 | 25.59182 |
3-element Vector{Float64}:
0.9292259065867788
0.018165149307614335
0.2226454658393477
These commands extract the conditional modes/means and (co-)variances of the random effects, that is the model’s “predictions” for the units (levels) of the grouping (random) factors.
1-element Vector{Array{Float64, 3}}:
[140.9671928188997 -20.604478452614167; -20.604478452614167 5.157784594104255;;; 140.9671928188997 -20.604478452614167; -20.604478452614167 5.157784594104255;;; 140.9671928188997 -20.604478452614167; -20.604478452614167 5.157784594104255;;; … ;;; 140.9671928188997 -20.604478452614167; -20.604478452614167 5.157784594104255;;; 140.9671928188997 -20.604478452614167; -20.604478452614167 5.157784594104255;;; 140.9671928188997 -20.604478452614167; -20.604478452614167 5.157784594104255]
The conditional covariances are hard to look at directly; they are usually visualized instead:
caterpillar, qqcaterpillar from MixedModelsMakie) display prediction intervals of the random effects per level; they are introduced in the sleepstudy analysis.shrinkageplot from MixedModelsMakie) visualize how the conditional modes are “shrunk” toward the grand mean relative to per-level estimates; they are the topic of Shrinkage of random effects.BlockDescription.This page was rendered from git revision 29e8d33 using Quarto 1.10.18 and Julia 1.12.7.