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.SEzpσ_subjσ_item
(Intercept)2347.135388.991626.37<1e-99332.0163342.8989
spkr: old189.159369.74032.710.0067134.1373
prec: maintain-586.479169.2142-8.47<1e-16117.8947
load: yes158.204069.83212.270.0235126.375639.5660
spkr: old & prec: maintain-179.122895.3684-1.880.0604
spkr: old & load: yes-20.177295.2571-0.210.8322
prec: maintain & load: yes-75.579095.2571-0.790.4275
spkr: old & prec: maintain & load: yes185.6897134.75221.380.1682
Residual712.4110

Note that the display here is more succinct than the standard REPL display:

using DisplayAs
kbm |> DisplayAs.Text
Linear 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)
ColumnVarianceStd.DevCorr.
subj(Intercept)110234.854332.016
spkr: old17992.803134.137+0.30
prec: maintain13899.151117.895-0.95-0.00
load: yes15970.795126.376-0.18+0.88+0.47
item(Intercept)117579.658342.899
load: yes1565.46739.566+0.77
Residual507529.442712.411

Similarly for BlockDescription, OptSummary and MixedModels.likelihoodratiotest:

BlockDescription(kbm)
rowssubjitemfixed
224BlkDiag
64DenseBlkDiag/Dense
8DenseDenseDense
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 value29112.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_rel1.0e-12
ftol_abs1.0e-8
xtol_rel0.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 evaluations430
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 value28801.3758
Return codeFTOL_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-dofdevianceχ²χ²-dofP(>χ²)
reaction ~ 1 + (1 | subj)31911
reaction ~ 1 + days + (1 + days | subj)617521593<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)