如果xtable不知道特殊命令,我该怎么做。例如,假设对轨道模型的估计,如下:
require(AER)
require(xtable)
attach(cars)
tob<-tobit(dist~speed)
summary(tob)
xtable(summary(tob))
detach(cars)
摘要的输出与线性模型的输出相比非常相似...为了使xtable理解,我想做什么,我想在Latex表中得到系数? Samme还有其他功能,例如来自summary(zeroinfl(<model>))
的{{1}}?
你们建议做什么?
答案 0 :(得分:4)
简短的回答是“将其转换为xtable类的理解”。例如,
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)
答案 1 :(得分:4)
这是您可以使用的另一个功能。它是为lm定义的xtable的修改版本。 即我刚刚为tobit案例修改了函数xtable.summary.lm。 它还将与其他xtable功能对齐
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))
希望它有助于获得理想的结果