【问题标题】:R Stargazer Getting p-values into one lineR Stargazer 将 p 值放入一行
【发布时间】:2020-06-15 06:10:58
【问题描述】:
stargazer(model1, model2, title = "Models", header=FALSE, 
          dep.var.labels.include = FALSE,
          column.labels = c("Count", "Percentage"),
          style = "ajs",
          report = "vcp*",
          single.row = TRUE)

这是我用 stargazer 创建回归表的代码。但是,p 值仍然低于系数估计值。如何让 p 值显示在系数估计值旁边?

【问题讨论】:

    标签: r stargazer


    【解决方案1】:

    您可以用 p 值替换标准误差。将模型放入列表中,这样您就可以使用lapply

    model1 <- lm(mpg ~ hp, mtcars)
    model2 <- lm(mpg ~ hp + cyl, mtcars)
    
    model.lst <- list(model1, model2)
    
    stargazer::stargazer(model.lst, title = "Models", header=FALSE, 
              dep.var.labels.include = FALSE,
              column.labels = c("Count", "Percentage"),
              style = "ajs",
              report = "vcs*",
              single.row = TRUE, type="text",
              se=lapply(model.lst, function(x) summary(x)$coef[,4]))
    # Models
    # =================================================================
    #                             Count                Percentage      
    #                               1                      2           
    # -----------------------------------------------------------------
    # hp                     -.068 (0.000)***         -.019 (.213)     
    # cyl                                          -2.265 (0.000)***   
    # Constant              30.099 (0.000)***      36.908 (0.000)***   
    # Observations                  32                     32          
    # R2                           .602                   .741         
    # Adjusted R2                  .589                   .723         
    # Residual Std. Error    3.863 (df = 30)        3.173 (df = 29)    
    # F Statistic         45.460*** (df = 1; 30) 41.422*** (df = 2; 29)
    # -----------------------------------------------------------------
    # Notes:              *P < .05                                     
    #                     **P < .01                                    
    #                     ***P < .001       
    

    请注意,texreg 也可以做到这一点,它可能看起来更干净一些,并且包维护得很好。

    texreg::screenreg(model.lst, single.row=TRUE, 
              reorder.coef=c(2:3, 1),
              custom.model.names=c("Count", "Percentage"),
              override.se=lapply(model.lst, function(x) summary(x)$coef[,4]),
              override.pvalues=lapply(model.lst, function(x) summary(x)$coef[,4]),
              digits=3
           )
    # ===================================================
    #              Count               Percentage        
    # ---------------------------------------------------
    # hp           -0.068 (0.000) ***  -0.019 (0.213)    
    # cyl                              -2.265 (0.000) ***
    # (Intercept)  30.099 (0.000) ***  36.908 (0.000) ***
    # ---------------------------------------------------
    # R^2           0.602               0.741            
    # Adj. R^2      0.589               0.723            
    # Num. obs.    32                  32                
    # ===================================================
    # *** p < 0.001; ** p < 0.01; * p < 0.05
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多