# Latex Output from MixedModels.jl

**URL:** https://discourse.julialang.org/t/latex-output-from-mixedmodels-jl/54797
**Category:** General Usage
**Tags:** latex
**Created:** [February 7, 2021, 3:24pm UTC](https://discourse.julialang.org/t/latex-output-from-mixedmodels-jl/54797 "2021-02-07T15:24:24Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![danielw2904](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielw2904/32/10890_2.png) [@danielw2904](https://discourse.julialang.org/u/danielw2904)
#### Post date: [February 7, 2021, 3:24pm UTC](https://discourse.julialang.org/t/latex-output-from-mixedmodels-jl/54797/1 "2021-02-07T15:24:24Z")

</div>

I was wondering if there is a LaTeX table package that supports MixedModels.jl similar to RegressionTables.jl for FixedEffectModels?

I have hacked something together usint PrettyTables.jl in case there is not:

```julia
function variance_components_latex(file, model)
    columnss = [reduce(hcat,
        [[y for y in propertynames(x)] for x in model.σs])..., ""]
    lens = [[length(x) for x in model.σs]... ; 1]
    revars = [string.(propertynames(model.σs))...; "Residual"]
    revars = reduce(vcat, [fill(x, y) for (x, y) in zip(revars, lens)])
   stds = [reduce(hcat, [[x[n] for n in propertynames(x)] for x in cremod.σs])..., model.σ]
   vars = abs2.(stds)
   open(file, "w") do io
        fmt = (v,i,j) -> j == 1 ? replace(v, '_' => "\\_") : v
        pretty_table(io, [revars columnss vars stds],
            ["" "Column" "Variance" "Std.Dev."],
            backend = :latex,
            tf = tf_latex_simple,
            formatters = (fmt,
            ft_printf("%5.7f", 3:4))
        )                                                                                                                                                    
    end
end

function coeftable_latex(file, model)
    tab_cols = reduce(hcat, coeftable(model).cols)
    tab_rown = coeftable(model).rownms
    tab_coln = permutedims(hcat(["", coeftable(model).colnms...]))
    dv = replace(model.formula.lhs.exorig |> string, '_' => "\\_")
    open(file, "w") do io
        fmt = (v,i,j) -> j == 1 ? replace(v, '_' => "\\_") : v
        pretty_table(io, [tab_rown tab_cols],
            [dv "" "" "" "" ; tab_coln];
            backend = :latex,
            tf = tf_latex_simple,
           formatters = (fmt,
           ft_latex_sn(3, [5]),
           ft_printf("%5.3f", 2:4))
     )
    end
end

```

---

<div class="post-metadata">

### Author: ![dmbates](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dmbates/32/44_2.png) [@dmbates](https://discourse.julialang.org/u/dmbates)
#### Post date: [February 7, 2021, 8:32pm UTC](https://discourse.julialang.org/t/latex-output-from-mixedmodels-jl/54797/2 "2021-02-07T20:32:27Z")

</div>

Thanks for the suggestion. Do you think that LaTeX or other tabular types of output should be included in the MixedModels package or in a separate package?

---

<div class="post-metadata">

### Author: ![danielw2904](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielw2904/32/10890_2.png) [@danielw2904](https://discourse.julialang.org/u/danielw2904)
#### Post date: [February 8, 2021, 5:26am UTC](https://discourse.julialang.org/t/latex-output-from-mixedmodels-jl/54797/3 "2021-02-08T05:26:03Z")

</div>

Personally, I don’t have a strong preference either way. RegressionTables.jl works fine for other packages and it feels unexpected that it doesn’t work for MixedModels. But PrettyTables is not a huge dependency so it could be included without much cost.

---

<div class="post-metadata">

### Author: ![palday](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palday/32/12640_2.png) [@palday](https://discourse.julialang.org/u/palday)
#### Post date: [February 11, 2021, 5:56pm UTC](https://discourse.julialang.org/t/latex-output-from-mixedmodels-jl/54797/4 "2021-02-11T17:56:19Z")

</div>

@danielw2904 This is a currently stillborn issue on our tracker ([https://github.com/JuliaStats/MixedModels.jl/issues/273](https://github.com/JuliaStats/MixedModels.jl/issues/273)), but it’s always good get an extra push. I also wrote [GPL’d R-Code](https://bitbucket.org/palday/lmerout/src/master/) that I could adapt and relicense for Julia.

I think the easy bit is converting the individual components to tabular format (e.g. `VarCorr` or `CoefTable`), but having the entire model summary in a single table is a bit harder. There’s nothing to stop wrapping multiple tables (`tabular`) in a single LaTeX `table` floating environment, but that’s not quite a single table. I have a proposal for a single table, but it looks nothing like the default `show` method for models in the REPL.

I think the solution is to add MIME/Markdown `show` methods to MixedModels.jl itself and maybe include support for `RegressionTables.jl` in the [`MixedModelsExtras.jl`](https://github.com/palday/MixedModelsExtras.jl) package that I’ve marked off (but not yet started filling in) for just such types of functionality. (ICC and potentially an inefficient implementation of the Kenward Roger approximation for the denominator degrees of freedom are other candidates.)

---

<div class="post-metadata">

### Author: ![palday](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palday/32/12640_2.png) [@palday](https://discourse.julialang.org/u/palday)
#### Post date: [February 26, 2021, 12:42pm UTC](https://discourse.julialang.org/t/latex-output-from-mixedmodels-jl/54797/5 "2021-02-26T12:42:34Z")

</div>

It looks like we’ll soon have Markdown support for our `show` methods ([Markdown show methods for our types by palday · Pull Request #474 · JuliaStats/MixedModels.jl · GitHub](https://github.com/JuliaStats/MixedModels.jl/pull/474)).

So you’ll be able to do this: `show(open("file.md", write=true), MIME"text/markdown", model)` or `show(MIME"text/markdown", model)`. With pandoc, you can then convert those quite easily to LaTeX or HTML as needed. And all of this without adding any extra dependencies.

I probably won’t get around to direct support for LaTeX a little bit, because there are some options to think about there (e.g. `booktabs` or not? what tricks do we do to decimal-point alignment? etc.). In other words: mostly a bit of a tedious time investment i don’t have at the moment, especially when Markdown can be converted to LaTeX via pandoc. 🙂

---

<div class="post-metadata">

### Author: ![jzr](https://avatars.discourse-cdn.com/v4/letter/j/eb9ed0/32.png) [@jzr](https://discourse.julialang.org/u/jzr)
#### Post date: [September 18, 2021, 12:04am UTC](https://discourse.julialang.org/t/latex-output-from-mixedmodels-jl/54797/6 "2021-09-18T00:04:25Z")

</div>

Does MixedModels.jl support multiple regressions in a single table, like [RegressionTables.jl](https://github.com/jmboehm/RegressionTables.jl) does?

cc @palday @dmbates @jmboehm

---

<div class="post-metadata">

### Author: ![jmboehm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jmboehm/32/2263_2.png) [@jmboehm](https://discourse.julialang.org/u/jmboehm)
#### Post date: [September 18, 2021, 9:34am UTC](https://discourse.julialang.org/t/latex-output-from-mixedmodels-jl/54797/7 "2021-09-18T09:34:11Z")

</div>

I can’t speak for MixedModels.jl, but RegressionTables.jl supports (in the latest version) any `<: RegressionModel`, and _should_ therefore work with output from MixedModels (I say _should_ because I haven’t tried… if there are problems, please file an issue).

---

<div class="post-metadata">

### Author: ![palday](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palday/32/12640_2.png) [@palday](https://discourse.julialang.org/u/palday)
#### Post date: [September 20, 2021, 3:17pm UTC](https://discourse.julialang.org/t/latex-output-from-mixedmodels-jl/54797/8 "2021-09-20T15:17:22Z")

</div>

@jzr No, and that’s because different models are different entities and so get different tables. 😉 That said, internally it’s all Markdown tables that are then converted to different MIME types using the stdlib, so for comparable models(\*) you should be able to concatenate those tables.

(\*) There’s a lot of fine print on comparable. For the fixed effects, yes, because you can extract those with `coeftable` quite easily, but for the random effects/variance components, … That’s something rather specific which doesn’t correspond directly to anything in the `RegressionModel` API. But if you’re just comparing fixed-effects estimates across different models, then RegressionTables.jl will probably be fine. I don’t see anything in the estimator field that corresponds to mixed models though – we’re not using OLS (we’re using penalized least squares) but that’s not what’s relevant for interpreting the model anyway. By default, we’re using the maximum-likelihood estimates, though we also support REML. We don’t support any other pseudo-/quasi “likelihoods”.
