首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用于不支持的函数的xtable (带R)

用于不支持的函数的xtable (带R)
EN

Stack Overflow用户
提问于 2011-05-07 00:22:33
回答 2查看 1.3K关注 0票数 6

如果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>))?你们有什么建议吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-05-07 03:08:28

这是您可以使用的另一个函数。它是为lm定义的xtable的修改版本。也就是说,我刚刚修改了tobit案例的函数xtable.summary.lm。它还将与其他xtable功能保持一致

代码语言:javascript
复制
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))

希望它能帮助你得到想要的结果

票数 4
EN

Stack Overflow用户

发布于 2011-05-07 01:53:50

简短的答案是“将其转换为xtable能够理解的类”。例如,

代码语言:javascript
复制
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
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5914238

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档