如果xtable不知道一个特殊的命令,我该怎么办?例如,假设一个tobit模型的估计,如下所示:
require(AER) require(xtable)
attach(cars)
tob<-tobit(dist~speed) summary(tob)
xtable(summary(tob))
detach(cars)
摘要的输出与线性模型的输出非常相似……我该怎么做才能让xtable理解我想要在Latex表中包含系数?使用其他函数的Samme,比如包pscl中的summary(zeroinfl(<model>))?你们有什么建议吗?
发布于 2011-05-07 03:08:28
这是您可以使用的另一个函数。它是为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))希望它能帮助你得到想要的结果
发布于 2011-05-07 01:53:50
简短的答案是“将其转换为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)https://stackoverflow.com/questions/5914238
复制相似问题