在r的stargazer中显示p值小于0.1的结果

8

我有一个回归系数在p值0.06的数据。stargazer的输出表格没有显示小数点(.)标志p值低于0.1。我如何使stargazer在输出表格中标志低于0.1的p值?

*如果需要,我会尝试找到一些p值在0.05以上和0.1以下的可重复示例。但希望这是一个简单问题,有一个快速的解决方案。


2
你可以使用参数 star.cutoffs = c(.1, .05, .01) 或者其他你喜欢的水平来完成它。如果你需要设置符号,你可以使用参数 star.char = c(".", "*", "**") 来指定每个显著性水平对应的符号。 - gfgm
这个可行,谢谢。你能把它发表为一个答案吗? - NBK
1
请注意,使用此解决方案时,您需要调整出现在表底部的注释,使用notes = c(“+ p <0.1; * p <0.05; ** p <0.01; *** p <0.001”)属性,并设置notes.append = FALSE。 - HoneyBuddha
1个回答

11

您可以使用star.cutoffsstar.char参数来实现此操作。以下是一些虚假数据,以演示:

library(stargazer)

# Generate some fake data
set.seed(10)
x <- rnorm(10)
x1 <- rnorm(10)
e <- rnorm(10)
y <- 10 + x + 2*x1 + e

# Estimate a model
m1 <- lm(y~x + x1)

# We can see that we have three different levels of sig at typical cutoffs
summary(m1)
#> 
#> Call:
#> lm(formula = y ~ x + x1)
#> 
#> Residuals:
#>      Min       1Q   Median       3Q      Max 
#> -1.12552 -0.20126 -0.06919  0.60370  0.76845 
#> 
#> Coefficients:
#>             Estimate Std. Error t value Pr(>|t|)    
#> (Intercept)   9.1012     0.3731  24.394 4.95e-08 ***
#> x             0.8389     0.3923   2.138   0.0698 .  
#> x1            1.7477     0.4094   4.269   0.0037 ** 
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> 
#> Residual standard error: 0.7851 on 7 degrees of freedom
#> Multiple R-squared:  0.8167, Adjusted R-squared:  0.7643 
#> F-statistic: 15.59 on 2 and 7 DF,  p-value: 0.002639

# We will make the 10% level a plus sign, and stars for .05, .01 and .001
stargazer(m1, type = "text",
          star.char = c("+", "*", "**", "***"),
          star.cutoffs = c(.1, .05, .01, .001))
#> 
#> ===============================================
#>                         Dependent variable:    
#>                     ---------------------------
#>                                  y             
#> -----------------------------------------------
#> x                             0.839+           
#>                               (0.392)          
#>                                                
#> x1                            1.748**          
#>                               (0.409)          
#>                                                
#> Constant                     9.101***          
#>                               (0.373)          
#>                                                
#> -----------------------------------------------
#> Observations                    10             
#> R2                             0.817           
#> Adjusted R2                    0.764           
#> Residual Std. Error       0.785 (df = 7)       
#> F Statistic            15.589** (df = 2; 7)    
#> ===============================================
#> Note:               *p<0.1; **p<0.05; ***p<0.01

这段文字是由reprex package(v0.2.0)于2018年08月08日创建的。


4
请注意,使用这个可行的解决方案时,您需要调整出现在表格底部的注释,使用 "notes = c("+ p<0.1; * p<0.05; ** p<0.01; *** p<0.001")" 属性,并将 "notes.append=FALSE" 设置。 - HoneyBuddha

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接