stargazer omit.labels的潜在错误

时间:2016-07-13 15:02:04

标签: r stargazer

stargazer软件包的5.2版中似乎存在一个错误,其中omit.label功能根据所包含模型的顺序不能始终如一地工作:

library(stargazer)
library(ggplot2)
as.data.frame(data("midwest"))
fit.1 <- lm(poptotal ~ popadults, data = midwest)
fit.2 <- lm(poptotal ~ popadults + state, data = midwest)

# Works, column listed as "Yes":
stargazer(fit.2, omit = c("state"), omit.labels = c("States"))
# Does not work, both columns listed as "No":
stargazer(fit.1, fit.2, omit = c("state"), omit.labels = c("States"))
# Works, first column "Yes", second "No":
stargazer(fit.2, fit.1, omit = c("state"), omit.labels = c("States"))

有没有人知道解决方法?

2 个答案:

答案 0 :(得分:1)

我只是使用add.lines属性为每列手动指定了虚拟对象。以你的例子:

stargazer(fit.1, fit.2, omit = c("state"),
    add.lines = list(
        c("States", "No", "Yes")
    )
)

答案 1 :(得分:1)

这是一种方法,使用包装函数自动生成add.lines值。这对我来说也有一种比单独的&#34;省略&#34;更自然的语法。和&#34; omit.labels&#34;参数。另外,您可以在没有指标的情况下省略变量:

XmlReader.GetAttribute

您在gazer<- function(...,indicate=NULL, staroptions=NULL){ dots <- list(...) if (is.null(indicate)==FALSE) { indicate.lines<-sapply(names(indicate), function(indic) ifelse( sapply(dots,function(x) length(grep(indic,names(coef(x))))>0 ) ,"Yes","No" ) ) indicate.lines<-rbind(unlist(indicate),indicate.lines) staroptions$omit <- c(staroptions$omit,names(indicate)) staroptions$add.lines <- c(split(indicate.lines,rep(1:ncol(indicate.lines), each=nrow(indicate.lines))),staroptions$add.lines) } do.call(stargazer,c(dots,staroptions)) }

列表中的indicate()和所有其他观星选项中提供了名称和标签列表

对于你的例子:

staroptions