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

Community
  • 1
  • 1
Ryan
  • 1,306
  • 1
  • 13
  • 20
  • 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 '11 at 15:32
  • @ Vincent, thats typically what i do, and if doing it repeatedly, i write a function. – richiemorrisroe Mar 28 '11 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 '14 at 17:49
  • For HTML [tables](https://strengejacke.wordpress.com/2015/06/05/beautiful-table-outputs-summarizing-mixed-effects-models-rstats) and [plots](http://strengejacke.de/sjPlot/sjp.lmer) check the [sjPlot](http://cran.r-project.org/web/packages/sjPlot) package. – radek Jun 12 '15 at 11:34
  • 1
    Have you tried the stargazer package? – RobertMyles May 21 '17 at 02:39

3 Answers3

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))
Philip Leifeld
  • 2,253
  • 15
  • 24
10

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

user20061
  • 444
  • 6
  • 12
Ramnath
  • 54,439
  • 16
  • 125
  • 152
  • +1 thx for the link. I was busy rewriting it myself, but apparently this has been done already. – Joris Meys Mar 28 '11 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 '11 at 16:02
  • @Joris, please start a community wiki, LaTeX tables are really a must. – aL3xa Mar 28 '11 at 17:18
  • @aL3xa : I made a community wiki here : http://stackoverflow.com/questions/5465314/tools-for-making-latex-tables-in-r 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 '11 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. – Paŭlo Ebermann Oct 07 '11 at 00:57
  • This link is dead. Any replacements? – galliwuzz Aug 09 '18 at 14:07
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.

Scott
  • 61
  • 1
  • 1