Skip to content

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.

julia
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.069078.191127.91<1e-99318.9314358.3855
spkr: old67.965919.08083.560.000467.0805
prec: maintain-333.703818.5949-17.95<1e-7158.9474
load: yes78.374119.16234.09<1e-0463.211419.6931
spkr: old & prec: maintain-21.569416.8440-1.280.2004
spkr: old & load: yes18.167016.84411.080.2808
prec: maintain & load: yes4.316516.84410.260.7977
spkr: old & prec: maintain & load: yes23.211216.84401.380.1682
Residual712.4110

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

julia
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)     101717.2454 318.9314
         spkr: old         4499.7962  67.0805 +0.70
         prec: maintain    3474.7975  58.9474 -0.71 -0.00
         load: yes         3995.6822  63.2114 +0.28 +0.88 +0.47
item     (Intercept)     128440.1457 358.3855
         load: yes          387.8169  19.6931 +0.80
Residual                 507529.4719 712.4110
 Number of obs: 1789; levels of grouping factors: 56, 32

  Fixed-effects parameters:
────────────────────────────────────────────────────────────────────────────────
                                             Coef.  Std. Error       z  Pr(>|z|)
────────────────────────────────────────────────────────────────────────────────
(Intercept)                             2182.07        78.1911   27.91    <1e-99
spkr: old                                 67.9659      19.0808    3.56    0.0004
prec: maintain                          -333.704       18.5949  -17.95    <1e-71
load: yes                                 78.3741      19.1623    4.09    <1e-04
spkr: old & prec: maintain               -21.5694      16.844    -1.28    0.2004
spkr: old & load: yes                     18.167       16.8441    1.08    0.2808
prec: maintain & load: yes                 4.31651     16.8441    0.26    0.7977
spkr: old & prec: maintain & load: yes    23.2112      16.844     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:

julia
VarCorr(kbm)
Column VarianceStd.DevCorr.
subj(Intercept)101717.2454318.9314
spkr: old4499.796267.0805+0.70
prec: maintain3474.797558.9474-0.71-0.00
load: yes3995.682263.2114+0.28+0.88+0.47
item(Intercept)128440.1457358.3855
load: yes387.816919.6931+0.80
Residual 507529.4719712.4110

Similarly for BlockDescription, OptSummary and MixedModels.likelihoodratiotest:

julia
BlockDescription(kbm)
rowssubjitemfixed
224BlkDiag
64DenseBlkDiag/Dense
9DenseDenseDense
julia
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
OptimizerLN_BOBYQA
Backendnlopt
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
xtol_zero_abs0.001
ftol_zero_abs1.0e-5
Result
Function evaluations317
Final parameter vector[0.4477, 0.066, -0.0592, 0.0249, 0.0672, 0.0578, 0.0852, 0.0, 0.0002, 0.0, 0.5031, 0.022, 0.0167]
Final objective value28801.3758
Return codeFTOL_REACHED
julia
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.)

julia
show(MIME("text/markdown"), m1)
|                                        |      Est. |      SE |      z |      p |   σ_subj |   σ_item |
|:-------------------------------------- | ---------:| -------:| ------:| ------:| --------:| --------:|
| (Intercept)                            | 2182.0690 | 78.1911 |  27.91 | <1e-99 | 318.9314 | 358.3855 |
| spkr: old                              |   67.9659 | 19.0808 |   3.56 | 0.0004 |  67.0805 |          |
| prec: maintain                         | -333.7038 | 18.5949 | -17.95 | <1e-71 |  58.9474 |          |
| load: yes                              |   78.3741 | 19.1623 |   4.09 | <1e-04 |  63.2114 |  19.6931 |
| spkr: old & prec: maintain             |  -21.5694 | 16.8440 |  -1.28 | 0.2004 |          |          |
| spkr: old & load: yes                  |   18.1670 | 16.8441 |   1.08 | 0.2808 |          |          |
| prec: maintain & load: yes             |    4.3165 | 16.8441 |   0.26 | 0.7977 |          |          |
| spkr: old & prec: maintain & load: yes |   23.2112 | 16.8440 |   1.38 | 0.1682 |          |          |
| Residual                               |  712.4110 |         |        |        |          |          |
julia
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.0690</td><td align="right">78.1911</td><td align="right">27.91</td><td align="right">&lt;1e-99</td><td align="right">318.9314</td><td align="right">358.3855</td></tr><tr><td align="left">spkr: old</td><td align="right">67.9659</td><td align="right">19.0808</td><td align="right">3.56</td><td align="right">0.0004</td><td align="right">67.0805</td><td align="right"> </td></tr><tr><td align="left">prec: maintain</td><td align="right">-333.7038</td><td align="right">18.5949</td><td align="right">-17.95</td><td align="right">&lt;1e-71</td><td align="right">58.9474</td><td align="right"> </td></tr><tr><td align="left">load: yes</td><td align="right">78.3741</td><td align="right">19.1623</td><td align="right">4.09</td><td align="right">&lt;1e-04</td><td align="right">63.2114</td><td align="right">19.6931</td></tr><tr><td align="left">spkr: old &amp; prec: maintain</td><td align="right">-21.5694</td><td align="right">16.8440</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.1670</td><td align="right">16.8441</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.8441</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.8440</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.4110</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.

julia
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.0690 & 78.1911 & 27.91 & <1e-99 & 318.9314 & 358.3855 \\
spkr: old & 67.9659 & 19.0808 & 3.56 & 0.0004 & 67.0805 &   \\
prec: maintain & -333.7038 & 18.5949 & -17.95 & <1e-71 & 58.9474 &   \\
load: yes & 78.3741 & 19.1623 & 4.09 & <1e-04 & 63.2114 & 19.6931 \\
spkr: old \& prec: maintain & -21.5694 & 16.8440 & -1.28 & 0.2004 &   &   \\
spkr: old \& load: yes & 18.1670 & 16.8441 & 1.08 & 0.2808 &   &   \\
prec: maintain \& load: yes & 4.3165 & 16.8441 & 0.26 & 0.7977 &   &   \\
spkr: old \& prec: maintain \& load: yes & 23.2112 & 16.8440 & 1.38 & 0.1682 &   &   \\
Residual & 712.4110 &  &  &  &  &  \\
\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.)

julia
show(MIME("text/xelatex"), m1)
\begin{tabular}
{l | r | r | r | r | r | r}
 & Est. & SE & z & p & σ\_subj & σ\_item \\
\hline
(Intercept) & 2182.0690 & 78.1911 & 27.91 & <1e-99 & 318.9314 & 358.3855 \\
spkr: old & 67.9659 & 19.0808 & 3.56 & 0.0004 & 67.0805 &   \\
prec: maintain & -333.7038 & 18.5949 & -17.95 & <1e-71 & 58.9474 &   \\
load: yes & 78.3741 & 19.1623 & 4.09 & <1e-04 & 63.2114 & 19.6931 \\
spkr: old \& prec: maintain & -21.5694 & 16.8440 & -1.28 & 0.2004 &   &   \\
spkr: old \& load: yes & 18.1670 & 16.8441 & 1.08 & 0.2808 &   &   \\
prec: maintain \& load: yes & 4.3165 & 16.8441 & 0.26 & 0.7977 &   &   \\
spkr: old \& prec: maintain \& load: yes & 23.2112 & 16.8440 & 1.38 & 0.1682 &   &   \\
Residual & 712.4110 &  &  &  &  &  \\
\end{tabular}

This output can also be written directly to file:

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