[R] LaTeX output with mlogit or multinom

Achim Zeileis Achim.Zeileis at uibk.ac.at
Wed Oct 27 01:06:14 CEST 2010

On Tue, 26 Oct 2010, Marc Schwartz wrote:

> On Oct 26, 2010, at 2:59 PM, Ben Hunter wrote:
>> Hi everyone,
>> Why am I having such a tough time finding a way to put an mlogit summary
>> table into latex? Everywhere I read says that using Sweave and latex is the
>> most sophisticated, dynamic way to get output, but it appears very limited
>> in this respect. I'm just starting out with Sweave and LaTeX and I've only
>> been working with R for about 5 months. I'm suspecting this is something
>> that just hasn't been done yet, but certainly there is a workaround I don't
>> know about. Hope so, anyway.
>> Thanks a lot.
>> Ben
> Ben,
> One thing to keep in mind is that the LaTeX related functions (save Sweave itself) are contributed by folks via third party packages. They are not part of the "core" R offering.
> The two primary packages that offer LaTeX related output for common R objects are xtable and Hmisc (via the latex() function). In both cases, the object class methods that are included likely reflect, to a large extent, the most commonly used R objects by the authors who are then motivated to write the functions. In turn, these also tend to represent common usage more generally.
> There may very well be someone out there who has created a specific function to generate LaTeX output for the two functions of interest here, but they may not have made them generally available for various reasons.
> That being said, if you can take the relevant content of the R objects generated by mlogit and/or multinom and construct a matrix or data frame from them, you can then use the xtable() methods for a matrix or data frame to generate formatted LaTeX output in your Sweave document. Since most relevant LaTeX output is tabular in nature, using either a matrix or data frame is a general purpose approach to getting the content you may desire, in lieu of having a method specifically for a particular R object.

Some months back I discussed with the "xtable" folks the possibility of 
including some default method leveraging the coefplot() function from the 
"lmtest" package which computes the usual table of coefficients/standard 
errors/test statistics/p-values. A quick and dirty hack would be the 

## load "xtable" and provide a new xtable() method for
## "coeftest" objects
xtable.coeftest <- function(x, ...) {
    xtable:::xtable.summary.lm(list(coef = unclass(x)), ...)

With that you can do xtable(coeftest(fitted_object)) for a rather wide 
class of models. See below for worked examples of mlogit() and multinom().


## mlogit() model from "mlogit" package
data("Fishing", package = "mlogit")
Fish <- mlogit.data(Fishing, varying = c(2:9),
   shape = "wide", choice = "mode")
fm_mlogit <- mlogit(mode ~ 0 | income, data = Fish)

## load "lmtest" to compute coeftest()

## export via xtable()

## multinom() model from "nnet" package
fm_multinom <- multinom(mode ~ income, data = Fishing)
## the coeftest() method is in "AER" package

> In addition, while this may not be a direction you wish to take, I did locate an Export plug in for the Rcmdr package that appears to have some relevant functionality for the summary.multinom() class. You may wish to consider that approach. More information is at:
>  http://cran.r-project.org/web/packages/RcmdrPlugin.Export/
> HTH,
> Marc Schwartz
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list