Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xtable for not supported functions (with R)

Tags:

r

statistics

what am I supposed to do, if xtable doesn't know a special command. For example assume the estimation of a tobit model, like this:

require(AER) require(xtable)

attach(cars)

tob<-tobit(dist~speed) summary(tob)

xtable(summary(tob))

detach(cars)

the output of summary is pretty similar compared to an output of a linear model... What can I do, to make xtable understand, that I want to have the coefficients in a Latex table? Samme with other functions like summary(zeroinfl(<model>)) from the pakage pscl? What would you guys recommend to do?

like image 802
user734124 Avatar asked May 06 '11 16:05

user734124


2 Answers

Here is another function that you can use. It is a modified version of the xtable defined for lm. i.e I have just modified the function xtable.summary.lm for the tobit case. It will also be aligned to other xtable functionalities

xtable.summary.tobit <- 
function (x, caption = NULL, label = NULL, align = NULL, digits = NULL, 
display = NULL, ...) 
{
 x <- data.frame(unclass(x$coef), check.names = FALSE)
 class(x) <- c("xtable", "data.frame")
 caption(x) <- caption
 label(x) <- label
 align(x) <- switch(1 + is.null(align), align, c("r", "r", 
     "r", "r", "r"))
 digits(x) <- switch(1 + is.null(digits), digits, c(0, 4, 
     4, 2, 4))
 display(x) <- switch(1 + is.null(display), display, c("s", 
     "f", "f", "f", "f"))
 return(x)
}
## Now this should give you the desired result
xtable(summary(tob))

Hope it helps in getting the desired result

like image 172
sayan dasgupta Avatar answered Sep 24 '22 02:09

sayan dasgupta


The short answer is "convert it to a class xtable understands". For example,

tmp <- summary(tob)
str(tmp) ## a list
names(tmp) ## the contents of tmp
str(tmp$coefficients) ## the class of the coeffients table ("coeftest")
is.matrix(tmp$coefficients) # TRUE
class(tmp$coefficients) <- "matrix"
xtable(tmp$coefficients)
like image 24
Ista Avatar answered Sep 27 '22 02:09

Ista