# Code: extended model support for mtable

March 22, 2011
By

(This article was first published on Left Censored » R, and kindly contributed to R-bloggers)

I finally got around to organizing and packaging my complete set of extended model support for mtable in Martin Elff’s `memisc` library. Here is a list of the models supported:

• `coxph`, `survreg` – Cox proportional hazards models and parametric survival models from the `survival` library.
• `aftreg`, `phreg`, `weibreg` – parametric AFT, proportional hazards, and Weibull models available from the `eha` library.
• `mer` – multilevel mixed effects models as provided by the `lme4` package. The model objects produced in the beta `lme4a` package are not supported.

Here’s the file: mtable-ext

It’s extremely easy to use, though I am sure there are some bugs and not all model features get reported. Here is an example of how to compare three Cox proportional hazard models as estimated with `coxph` (yes, I know, the Breslow and Exact models are the same; Exact was refusing to converge so I just stuck the Breslow model in to get the example done):

```library(survival)
library(memisc)
source("mtable-ext.R")

> Efron <- coxph(Surv(start, end, switch) ~ Poll + Government + OldParty +
+                Experience + Right + Members, robust = TRUE, data = Sejm,
+                method = "efron")

> Breslow <- coxph(Surv(start, end, switch) ~ Poll + Government + OldParty +
+                  Experience + Right + Members, robust = TRUE, data = Sejm,
+                  method = "breslow")

> Exact <- coxph(Surv(start, end, switch) ~ Poll + Government + OldParty +
+                Experience + Right + Members, robust = TRUE, data = Sejm,
+                method = "exact")

mtable(Efron, Breslow, Exact)

[... some model call info ...]

=============================================
Efron    Breslow    Exact
---------------------------------------------
Poll            -2.120*** -1.931*** -1.931***
(0.477)   (0.430)   (0.430)
Government      -1.603*   -1.461*   -1.461*
(0.706)   (0.684)   (0.684)
OldParty        -0.186    -0.279    -0.279
(0.243)   (0.209)   (0.209)
Experience      -0.195    -0.198    -0.198
(0.167)   (0.156)   (0.156)
Right            1.427***  1.290***  1.290***
(0.198)   (0.178)   (0.178)
Members         -0.002    -0.003    -0.003
(0.007)   (0.007)   (0.007)
---------------------------------------------
Log-likelihood   -818.487  -832.625  -832.625
AIC              1648.973  1677.250  1677.250
BIC              1701.297  1729.574  1729.574
N               45280     45280     45280
=============================================```

To convert the `mtable` object into a $text{LaTeX{}}$ table, you just need to apply the `toLatex` function:

`toLatex(mtable(Efron, Breslow, Exact))`

Of course, many formatting options are available. See the documentation for details.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...