Alternative display and output formats
In the documentation, we have presented the output from MixedModels.jl in the same format you will see when working in the REPL. You may have noticed, however, that output from other packages received pretty printing. For example, DataFrames are converted into nice HTML tables. In MixedModels, we recently (v3.2.0) introduced limited support for such pretty printing. (For more details on how the print and display system in Julia works, check out this NextJournal post.)
In particular, we have defined Markdown output, i.e. show methods, for our types, which can be easily translated into HTML, LaTeX or even a MS Word Document using tools such as pandoc. Packages like IJulia and Documenter can often detect the presence of these display options and use them automatically.
using MixedModels
form = @formula(rt_trunc ~ 1 + spkr * prec * load +
(1 + load | item) +
(1 + spkr + prec + load | subj))
kbm = fit(MixedModel, form, MixedModels.dataset(:kb07))| Est. | SE | z | p | σ_subj | σ_item | |
|---|---|---|---|---|---|---|
| (Intercept) | 2347.1353 | 88.9916 | 26.37 | <1e-99 | 332.0163 | 342.8989 |
| spkr: old | 189.1593 | 69.7403 | 2.71 | 0.0067 | 134.1373 | |
| prec: maintain | -586.4791 | 69.2142 | -8.47 | <1e-16 | 117.8947 | |
| load: yes | 158.2040 | 69.8321 | 2.27 | 0.0235 | 126.3756 | 39.5660 |
| spkr: old & prec: maintain | -179.1228 | 95.3684 | -1.88 | 0.0604 | ||
| spkr: old & load: yes | -20.1772 | 95.2571 | -0.21 | 0.8322 | ||
| prec: maintain & load: yes | -75.5790 | 95.2571 | -0.79 | 0.4275 | ||
| spkr: old & prec: maintain & load: yes | 185.6897 | 134.7522 | 1.38 | 0.1682 | ||
| Residual | 712.4110 |
Note that the display here is more succinct than the standard REPL display:
using DisplayAs
kbm |> DisplayAs.TextLinear mixed model fit by maximum likelihood
rt_trunc ~ 1 + spkr + prec + load + spkr & prec + spkr & load + prec & load + spkr & prec & load + (1 + load | item) + (1 + spkr + prec + load | subj)
logLik -2 logLik AIC AICc BIC
-14400.6879 28801.3758 28845.3758 28845.9489 28966.1429
Variance components:
Column Variance Std.Dev. Corr.
subj (Intercept) 110234.854 332.016
spkr: old 17992.803 134.137 +0.30
prec: maintain 13899.151 117.895 -0.95 -0.00
load: yes 15970.795 126.376 -0.18 +0.88 +0.47
item (Intercept) 117579.658 342.899
load: yes 1565.467 39.566 +0.77
Residual 507529.442 712.411
Number of obs: 1789; levels of grouping factors: 56, 32
Fixed-effects parameters:
──────────────────────────────────────────────────────────────────────────────
Coef. Std. Error z Pr(>|z|)
──────────────────────────────────────────────────────────────────────────────
(Intercept) 2347.14 88.9916 26.37 <1e-99
spkr: old 189.159 69.7403 2.71 0.0067
prec: maintain -586.479 69.2142 -8.47 <1e-16
load: yes 158.204 69.8321 2.27 0.0235
spkr: old & prec: maintain -179.123 95.3684 -1.88 0.0604
spkr: old & load: yes -20.1772 95.2571 -0.21 0.8322
prec: maintain & load: yes -75.579 95.2571 -0.79 0.4275
spkr: old & prec: maintain & load: yes 185.69 134.752 1.38 0.1682
──────────────────────────────────────────────────────────────────────────────This brevity is intentional: we wanted these types work well with traditional academic publishing constraints on tables. The summary for a model fit presented in the REPL does not mesh well with being treated a single table (with columns shared between the random and fixed effects). In our experience, this leads to difficulties in typesetting the resulting tables. We nonetheless encourage users to report fit statistics such as the log likelihood or AIC as part of the caption of their table. If the correlation parameters in the random effects are of interest, then VarCorr can also be pretty printed:
VarCorr(kbm)| Column | Variance | Std.Dev | Corr. | |||
|---|---|---|---|---|---|---|
| subj | (Intercept) | 110234.854 | 332.016 | |||
| spkr: old | 17992.803 | 134.137 | +0.30 | |||
| prec: maintain | 13899.151 | 117.895 | -0.95 | -0.00 | ||
| load: yes | 15970.795 | 126.376 | -0.18 | +0.88 | +0.47 | |
| item | (Intercept) | 117579.658 | 342.899 | |||
| load: yes | 1565.467 | 39.566 | +0.77 | |||
| Residual | 507529.442 | 712.411 |
Similarly for BlockDescription, OptSummary and MixedModels.likelihoodratiotest:
BlockDescription(kbm)| rows | subj | item | fixed |
|---|---|---|---|
| 224 | BlkDiag | ||
| 64 | Dense | BlkDiag/Dense | |
| 8 | Dense | Dense | Dense |
kbm.optsum| Initialization | |
| Initial parameter vector | [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0] |
| Initial objective value | 29112.99046012829 |
| Optimizer settings | |
| Optimizer (from NLopt) | LN_BOBYQA |
Lower bounds | [0.0, -Inf, -Inf, -Inf, 0.0, -Inf, -Inf, 0.0, -Inf, 0.0, 0.0, -Inf, 0.0] |
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, 1.0e-10, 1.0e-10, 1.0e-10, 1.0e-10, 1.0e-10, 1.0e-10, 1.0e-10, 1.0e-10, 1.0e-10, 1.0e-10] |
initial_step | [0.75, 1.0, 1.0, 1.0, 0.75, 1.0, 1.0, 0.75, 1.0, 0.75, 0.75, 1.0, 0.75] |
maxfeval | -1 |
| Result | |
| Function evaluations | 430 |
| Final parameter vector | [0.466, 0.0572, -0.1578, -0.0323, 0.1794, 0.0499, 0.1744, 0.0, -0.0001, 0.0, 0.4813, 0.0428, 0.0354] |
| Final objective value | 28801.3758 |
| Return code | FTOL_REACHED |
m0 = fit(MixedModel, @formula(reaction ~ 1 + (1|subj)), MixedModels.dataset(:sleepstudy))
m1 = fit(MixedModel, @formula(reaction ~ 1 + days + (1+days|subj)), MixedModels.dataset(:sleepstudy))
MixedModels.likelihoodratiotest(m0,m1)| model-dof | deviance | χ² | χ²-dof | P(>χ²) | |
|---|---|---|---|---|---|
| reaction ~ 1 + (1 | subj) | 3 | 1911 | |||
| reaction ~ 1 + days + (1 + days | subj) | 6 | 1752 | 159 | 3 | <1e-33 |
To explicitly invoke this behavior, we must specify the right show method:
show(MIME("text/markdown"), m1)| | Est. | SE | z | p | σ_subj | σ_item | |:-------------------------------------- |:--------- | --------:| -----:| ------:| --------:| --------:| | (Intercept) | 2347.1353 | 88.9916 | 26.37 | <1e-99 | 332.0163 | 342.8989 | | spkr: old | 189.1593 | 69.7403 | 2.71 | 0.0067 | 134.1373 | | | prec: maintain | -586.4791 | 69.2142 | -8.47 | <1e-16 | 117.8947 | | | load: yes | 158.2040 | 69.8321 | 2.27 | 0.0235 | 126.3756 | 39.5660 | | spkr: old & prec: maintain | -179.1228 | 95.3684 | -1.88 | 0.0604 | | | | spkr: old & load: yes | -20.1772 | 95.2571 | -0.21 | 0.8322 | | | | prec: maintain & load: yes | -75.5790 | 95.2571 | -0.79 | 0.4275 | | | | spkr: old & prec: maintain & load: yes | 185.6897 | 134.7522 | 1.38 | 0.1682 | | | | Residual | 712.4110 | | | | | |
(The raw and not rendered output is intentionally shown here.)
In the future, we may directly support HTML and LaTeX as MIME types.
This output can also be written directly to file:
show(open("model.md", "w"), MIME("text/markdown"), kbm)