Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How extract regression results from lme, lmer, glmer to Latex?

Tags:

r

latex

I'm fitting models with lme, lmer and glmer. I need to construct tables with the summary() objects and export to Latex showing my results. xtable, mtable, and apsrtable do not work. I saw a previous post (link below) with a solution for lme4 objects, but not for these ones.

http://leftcensored.skepsi.net/2011/03/13/code-latex-tables-for-lme4-models/

These are two examples of the models I'm fitting:

lme(y ~  time, data, na.action=na.omit, method="REML", random = ~ 1 | subject, control=lmeControl(msMaxIter = 200, msVerbose = TRUE))

glmer(y ~ time + (time | subject), data, family=binomial(link = "logit"), REML=T, control=list(maxIter = 800, maxFN=1000, msVerbose = TRUE))

Any help?

thanks

like image 382
user1172558 Avatar asked Feb 23 '12 04:02

user1172558


2 Answers

I just found out that there exists a coef method for summary.mer objects which provides all the necessary data (for the fixed effects). The returned object (after coercion to data.frame) can than easily be handed over to the formatting package of choice (e.g., xtable or ascii).
See the following example (which only produces the usable data.frame):

require(lme4)

gm1 <- glmer(cbind(incidence, size - incidence) ~ period + (1 | herd),
              family = binomial, data = cbpp)

(res.table <- as.data.frame(coef(summary(gm1))))
##             Estimate Std. Error z value        Pr(>|z|)
## (Intercept)  -1.3985     0.2279  -6.137 0.0000000008416
## period2      -0.9923     0.3054  -3.249 0.0011562741408
## period3      -1.1287     0.3260  -3.462 0.0005368285553
## period4      -1.5804     0.4288  -3.686 0.0002282168737
like image 151
Henrik Avatar answered Oct 02 '22 19:10

Henrik


Edit:

At the time of edit the lme4 package has updated and memisc no longer works with these objects. Package texreg is an alternative. I've left this answer up in case memisc gets updated and it starts working again.

The memisc package does lme4 tables:

Here's a snippet of some code I wrote:

GPusenonMH=lmer(GPEtc_c~Age.y+Measure+Gender+Marital2+Work2+(1|NHS), family="poisson", data=subset(lemurdata, Measure %in% c(1,3)))

model1=mtable(GPusetotal, GPuseMH, GPusenonMH, summary.stats=FALSE)

toLatex(model1)

Obviously you could turn summary.stats=TRUE if you wanted any of that stuff.

Note that the dcolumn and booktabs Latex packages are both used by default so either put them in your Latex preamble or turn them off using the commands in the helpfile (useBooktabs=FALSE, useDcolumn=FALSE).

like image 42
Chris Beeley Avatar answered Oct 02 '22 20:10

Chris Beeley