Xtable for unsupported features (with R)

what should i do if xtable doesn't know a special command. For example, suppose a model of type tobit is evaluated:

require(AER) require(xtable)

attach(cars)

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

xtable(summary(tob))

detach(cars)

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

+6
source share
2 answers

Here is another feature you can use. This is a modified version of xxtable defined for lm. ie I just changed the xtable.summary.lm function for the tobit case. It will also be tied to other functional functions.

 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)) 

I hope this helps to get the desired result.

+4
source

The short answer is "convert it to a class that understands." For instance,

 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) 
+4
source

Source: https://habr.com/ru/post/887463/


All Articles