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, HTML and LaTeX output, i.e. show methods, for our types. Note that the Markdown output can also be easily and more flexibly translated into HTML, LaTeX (e.g. with booktabs) 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))
contr = Dict(:spkr => EffectsCoding(),
             :prec => EffectsCoding(),
             :load => EffectsCoding(),
             :item => Grouping(),
             :subj => Grouping())
kbm = fit(MixedModel, form, MixedModels.dataset(:kb07); contrasts=contr)
Est.SEzpσ_subjσ_item
(Intercept)2182.068978.192727.91<1e-99318.9583358.3826
spkr: old67.965919.08053.560.000467.0778
prec: maintain-333.703818.5950-17.95<1e-7158.9492
load: yes78.374119.16544.09<1e-0463.204819.8060
spkr: old & prec: maintain-21.569416.8439-1.280.2004
spkr: old & load: yes18.166916.84401.080.2808
prec: maintain & load: yes4.316516.84400.260.7977
spkr: old & prec: maintain & load: yes23.211216.84391.380.1682
Residual712.4069

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)     101734.3871 318.9583
         spkr: old         4499.4368  67.0778 +0.70
         prec: maintain    3475.0109  58.9492 -0.71 -0.00
         load: yes         3994.8513  63.2048 +0.28 +0.88 +0.47
item     (Intercept)     128438.0699 358.3826
         load: yes          392.2779  19.8060 +0.79
Residual                 507523.5891 712.4069
 Number of obs: 1789; levels of grouping factors: 56, 32

  Fixed-effects parameters:
───────────────────────────────────────────────────────────────────────────────
                                            Coef.  Std. Error       z  Pr(>|z|)
───────────────────────────────────────────────────────────────────────────────
(Intercept)                             2182.07       78.1927   27.91    <1e-99
spkr: old                                 67.9659     19.0805    3.56    0.0004
prec: maintain                          -333.704      18.595   -17.95    <1e-71
load: yes                                 78.3741     19.1654    4.09    <1e-04
spkr: old & prec: maintain               -21.5694     16.8439   -1.28    0.2004
spkr: old & load: yes                     18.1669     16.844     1.08    0.2808
prec: maintain & load: yes                 4.3165     16.844     0.26    0.7977
spkr: old & prec: maintain & load: yes    23.2112     16.8439    1.38    0.1682
───────────────────────────────────────────────────────────────────────────────

This brevity is intentional: we wanted these types to 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 as 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 VarianceStd.DevCorr.
subj(Intercept)101734.3871318.9583
spkr: old4499.436867.0778+0.70
prec: maintain3475.010958.9492-0.71-0.00
load: yes3994.851363.2048+0.28+0.88+0.47
item(Intercept)128438.0699358.3826
load: yes392.277919.8060+0.79
Residual 507523.5891712.4069

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 value29340.042234597688
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
maxtime-1.0
Result
Function evaluations339
Final parameter vector[0.4477, 0.066, -0.0592, 0.0249, 0.0672, 0.0579, 0.0852, 0.0, 0.0, 0.0, 0.5031, 0.022, 0.017]
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. (The raw and not rendered output is intentionally shown here.)

show(MIME("text/markdown"), m1)
|                                        |      Est. |      SE |      z |      p |   σ_subj |   σ_item |
|:-------------------------------------- | ---------:| -------:| ------:| ------:| --------:| --------:|
| (Intercept)                            | 2182.0689 | 78.1927 |  27.91 | <1e-99 | 318.9583 | 358.3826 |
| spkr: old                              |   67.9659 | 19.0805 |   3.56 | 0.0004 |  67.0778 |          |
| prec: maintain                         | -333.7038 | 18.5950 | -17.95 | <1e-71 |  58.9492 |          |
| load: yes                              |   78.3741 | 19.1654 |   4.09 | <1e-04 |  63.2048 |  19.8060 |
| spkr: old & prec: maintain             |  -21.5694 | 16.8439 |  -1.28 | 0.2004 |          |          |
| spkr: old & load: yes                  |   18.1669 | 16.8440 |   1.08 | 0.2808 |          |          |
| prec: maintain & load: yes             |    4.3165 | 16.8440 |   0.26 | 0.7977 |          |          |
| spkr: old & prec: maintain & load: yes |   23.2112 | 16.8439 |   1.38 | 0.1682 |          |          |
| Residual                               |  712.4069 |         |        |        |          |          |
show(MIME("text/html"), m1)
<table><tr><th align="left"></th><th align="right">Est.</th><th align="right">SE</th><th align="right">z</th><th align="right">p</th><th align="right">σ_subj</th><th align="right">σ_item</th></tr><tr><td align="left">&#40;Intercept&#41;</td><td align="right">2182.0689</td><td align="right">78.1927</td><td align="right">27.91</td><td align="right">&lt;1e-99</td><td align="right">318.9583</td><td align="right">358.3826</td></tr><tr><td align="left">spkr: old</td><td align="right">67.9659</td><td align="right">19.0805</td><td align="right">3.56</td><td align="right">0.0004</td><td align="right">67.0778</td><td align="right"> </td></tr><tr><td align="left">prec: maintain</td><td align="right">-333.7038</td><td align="right">18.5950</td><td align="right">-17.95</td><td align="right">&lt;1e-71</td><td align="right">58.9492</td><td align="right"> </td></tr><tr><td align="left">load: yes</td><td align="right">78.3741</td><td align="right">19.1654</td><td align="right">4.09</td><td align="right">&lt;1e-04</td><td align="right">63.2048</td><td align="right">19.8060</td></tr><tr><td align="left">spkr: old &amp; prec: maintain</td><td align="right">-21.5694</td><td align="right">16.8439</td><td align="right">-1.28</td><td align="right">0.2004</td><td align="right"> </td><td align="right"> </td></tr><tr><td align="left">spkr: old &amp; load: yes</td><td align="right">18.1669</td><td align="right">16.8440</td><td align="right">1.08</td><td align="right">0.2808</td><td align="right"> </td><td align="right"> </td></tr><tr><td align="left">prec: maintain &amp; load: yes</td><td align="right">4.3165</td><td align="right">16.8440</td><td align="right">0.26</td><td align="right">0.7977</td><td align="right"> </td><td align="right"> </td></tr><tr><td align="left">spkr: old &amp; prec: maintain &amp; load: yes</td><td align="right">23.2112</td><td align="right">16.8439</td><td align="right">1.38</td><td align="right">0.1682</td><td align="right"> </td><td align="right"> </td></tr><tr><td align="left">Residual</td><td align="right">712.4069</td><td align="right"></td><td align="right"></td><td align="right"></td><td align="right"></td><td align="right"></td></tr></table>

Note for that LaTeX, the column labels for the random effects are slightly changed: σ is placed into math mode and escaped and the grouping variable is turned into a subscript. Similarly for the likelihood ratio test, the χ² is escaped into math mode. This transformation improves pdfLaTeX and journal compatibility, but also means that XeLaTeX and LuaTeX may use a different font at this point.

show(MIME("text/latex"), m1)
\begin{tabular}
{l | r | r | r | r | r | r}
 & Est. & SE & z & p & $\sigma_\text{subj}$ & $\sigma_\text{item}$ \\
\hline
(Intercept) & 2182.0689 & 78.1927 & 27.91 & <1e-99 & 318.9583 & 358.3826 \\
spkr: old & 67.9659 & 19.0805 & 3.56 & 0.0004 & 67.0778 &   \\
prec: maintain & -333.7038 & 18.5950 & -17.95 & <1e-71 & 58.9492 &   \\
load: yes & 78.3741 & 19.1654 & 4.09 & <1e-04 & 63.2048 & 19.8060 \\
spkr: old \& prec: maintain & -21.5694 & 16.8439 & -1.28 & 0.2004 &   &   \\
spkr: old \& load: yes & 18.1669 & 16.8440 & 1.08 & 0.2808 &   &   \\
prec: maintain \& load: yes & 4.3165 & 16.8440 & 0.26 & 0.7977 &   &   \\
spkr: old \& prec: maintain \& load: yes & 23.2112 & 16.8439 & 1.38 & 0.1682 &   &   \\
Residual & 712.4069 &  &  &  &  &  \\
\end{tabular}

This escaping behavior can be disabled by specifying "text/xelatex" as the MIME type. (Note that other symbols may still be escaped, as the internal conversion uses the Markdown module from the standard library, which performs some escaping on its own.)

show(MIME("text/xelatex"), m1)
\begin{tabular}
{l | r | r | r | r | r | r}
 & Est. & SE & z & p & σ\_subj & σ\_item \\
\hline
(Intercept) & 2182.0689 & 78.1927 & 27.91 & <1e-99 & 318.9583 & 358.3826 \\
spkr: old & 67.9659 & 19.0805 & 3.56 & 0.0004 & 67.0778 &   \\
prec: maintain & -333.7038 & 18.5950 & -17.95 & <1e-71 & 58.9492 &   \\
load: yes & 78.3741 & 19.1654 & 4.09 & <1e-04 & 63.2048 & 19.8060 \\
spkr: old \& prec: maintain & -21.5694 & 16.8439 & -1.28 & 0.2004 &   &   \\
spkr: old \& load: yes & 18.1669 & 16.8440 & 1.08 & 0.2808 &   &   \\
prec: maintain \& load: yes & 4.3165 & 16.8440 & 0.26 & 0.7977 &   &   \\
spkr: old \& prec: maintain \& load: yes & 23.2112 & 16.8439 & 1.38 & 0.1682 &   &   \\
Residual & 712.4069 &  &  &  &  &  \\
\end{tabular}

This output can also be written directly to file:

open("model.md", "w") do io
    show(io, MIME("text/markdown"), kbm)
end