20

Does anyone know a way to produce a nice publication quality LaTeX table from an lme4 mer object? Neither the xtable method (package xtable) nor the latex method (package Hmisc) know how to deal with mer objects.

For example, given this fit:

library(lme4)    
fm1 <- lmer(Reaction ~ Days + (Days|Subject), sleepstudy)

Are there any options for producing a nice LaTeX table of the coefficient estimates for both the fixed and random effects?

EDIT:

Because this is somewhat buried in the comment threads below, note that a community wiki is in development for R LaTeX tables: Tools for making latex tables in R

5
  • 1
    xtable can take matrices and data frames as input. Why don't you just extract your quantities of interest from the model and feed them to xtable as a matrix? Alternatively, try apsrtable. It has a good extension system which makes it easy to add new models.
    – Vincent
    Mar 28, 2011 at 15:32
  • @ Vincent, thats typically what i do, and if doing it repeatedly, i write a function. Mar 28, 2011 at 18:06
  • The tools on the wiki certainly work for fixed effects but not for random effects. Looking for answer to OP on the latter.
    – bshor
    Jul 18, 2014 at 17:49
  • For HTML tables and plots check the sjPlot package.
    – radek
    Jun 12, 2015 at 11:34
  • 1
    Have you tried the stargazer package? May 21, 2017 at 2:39

3 Answers 3

17

The answer may be a bit late, but perhaps somebody may find it interesting:

library("texreg")
texreg(fm1)

To typeset multiple lme4 or other models side by side, use something like this:

texreg(list(fm1, fm2))
0
10

Here is a blog post that seems tailor made for this situation Latex Tables for lme4 Models

6
  • +1 thx for the link. I was busy rewriting it myself, but apparently this has been done already.
    – Joris Meys
    Mar 28, 2011 at 15:39
  • 2
    @ Joris. There is a lot of excellent code out there on latex tables for different models, but I think they are spread far and wide. I have been thinking of posting a community wiki to gather all sources in one place, but don't think I have the necessary reputation points to do that. Do you think that would be something of interest to you?
    – Ramnath
    Mar 28, 2011 at 16:02
  • @Joris, please start a community wiki, LaTeX tables are really a must.
    – aL3xa
    Mar 28, 2011 at 17:18
  • @aL3xa : I made a community wiki here : stackoverflow.com/questions/5465314/… It's not a wiki yet, but it is flagged so soon a moderator should convert it to wiki. I need 10000 rep to do that, so I'm 320 short...
    – Joris Meys
    Mar 28, 2011 at 21:33
  • 3
    We want to build a knowledge base here, not just a link collection. Your answer would be better if you could extract the essence of the linked article in your answer. Oct 7, 2011 at 0:57
6

I may have a hacky solution. I wanted the same thing, specifically the table of coefficients from a glmer model fit (the estimates, SEs, z, and p values). Finding the right part of the summary output and feeding that into xtable seems to have done the trick. Apologies for not supplying reproducible code & data, but from your original example:

fm1 <- lmer(Reaction ~ Days + (Days|Subject), sleepstudy)
xtable(summary(fm1)@coef)

Should give you the table of coefficients, SEs, etc. Note that it just gives the values, not the extra dressing-up of significance stars, etc.

1
  • 4
    coef(summary(fm1)) is better than summary(fm1)@coef -- it should work in any version of lme4
    – Ben Bolker
    Sep 12, 2013 at 22:14

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.