【问题标题】:Stargazer: omit stars for constant onlyStargazer:仅在常量中省略星星
【发布时间】:2015-04-06 22:22:51
【问题描述】:

在报告回归结果时,有时在常数项中包含统计显着性星号很俗气。是否可以配置stargazer 为回归变量保留星号,但不是为常数项?

fit <- lm(rating ~ complaints, data=attitude)
stargazer(fit)

【问题讨论】:

    标签: r stargazer


    【解决方案1】:

    基本上,答案是使用stargazerp 参数。从那里,我只需要编写一个(一系列)函数,它采用回归拟合列表并返回 p 值向量列表。然后我手动将截距的 p 值更改为 1,并且很快,截距上没有俗气的星星。此外,无需手动 LaTeX 编辑即可重现!

    commarobust <- function(fit){
      require(sandwich)
      require(lmtest)
      coeftest(fit,vcovHC(fit, type="HC2"))
    }
    
    getrobustps <- function(fit){
      robustfit <- commarobust(fit)
      ps <- robustfit[,4]
      ps["(Intercept)"] <- 1
      return(ps)
    }
    
    makerobustpslist <- function(fitlist){
      return(lapply(fitlist, FUN=getrobustps) )
    }
    

    然后在观星者通话中:

    stargazer(fit_1, fit_2, fit_3, fit_4, fit_5, 
              p=makerobustpslist(list(fit_1, fit_2, fit_3, fit_4, fit_5)))
    

    像魅力一样工作。

    【讨论】:

      【解决方案2】:

      您也可以使用broom 包将拟合结果转换为数据框,然后为您的内容添加星标:

      library("broom")
      mod <- lm(mpg ~ wt + qsec, data = mtcars)
      DF <- tidy(mod)
      DF$stars <- c("", "***", "***") # inspect and add manually, or automate
      

      xtable 包可用于将其格式化为 LaTeX 或其他格式。

      【讨论】:

      • stargazer 的默认值为 Latex。 OP 应该说明为什么他不能只编辑 HTML 或 Latex 输出。
      • 手动编辑 LaTeX 输出是最后的解决方案(我可能最终会使用)但它并不理想 - 主要是因为表格不能直接从代码中重现。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-10
      • 2016-05-26
      • 2018-10-22
      • 1970-01-01
      • 2021-11-15
      相关资源
      最近更新 更多