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?
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
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With