R具有一定的显着性代码来确定统计显着性。例如,在下面的示例中,点.
表示10%级别的显着性(请参阅下面的示例输出)。
很难看到点,特别是当我复制粘贴到Excel并在Times New Roman中显示它时。
我想改变它:
*
=显着为10%**
=显着为5%***
=显着为1%我有办法做到这一点吗?
> y = c(1,2,3,4,5,6,7,8)
> x = c(1,3,2,4,5,6,8,7)
> summary(lm(y~x))
Call:
lm(formula = y ~ x)
Residuals:
Min 1Q Median 3Q Max
-1.0714 -0.3333 0.0000 0.2738 1.1191
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.2143 0.6286 0.341 0.74480
x 0.9524 0.1245 7.651 0.00026 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.8067 on 6 degrees of freedom
Multiple R-squared: 0.907, Adjusted R-squared: 0.8915
F-statistic: 58.54 on 1 and 6 DF, p-value: 0.0002604
答案 0 :(得分:5)
您可以使用
创建自己的格式化功能mystarformat <- function(x) symnum(x, corr = FALSE, na = FALSE,
cutpoints = c(0, 0.01, 0.05, 0.1, 1),
symbols = c("***", "**", "*", " "))
您可以编写自己的系数格式化程序
show_coef <- function(mm) {
mycoef<-data.frame(coef(summary(mm)), check.names=F)
mycoef$signif = mystarformat(mycoef$`Pr(>|t|)`)
mycoef$`Pr(>|t|)` = format.pval(mycoef$`Pr(>|t|)`)
mycoef
}
然后使用您的模型,您可以使用
运行它mm <- lm(y~x)
show_coef(mm)
# Estimate Std. Error t value Pr(>|t|) signif
# (Intercept) 0.2142857 0.6285895 0.3408993 0.7447995
# x 0.9523810 0.1244793 7.6509206 0.0002604 ***
答案 1 :(得分:0)
很抱歉收到您的回复,但我找到了一个很好的解决方案。 只需执行以下操作:
install.packages("stargazer")
library(stargazer)
stargazer(your_regression, type = "text")
这将以所需的格式以精美的方式显示所有内容。
注意:如果不使用type = "text"
,则将获得LaTeX代码。
答案 2 :(得分:0)
应该意识到,与其他统计软件(如STATA)相比,观星者软件包报告的重要性水平具有不同的规模。
在R(占星师)中,您得到# (* p<0.1; ** p<0.05; *** p<0.01)
。而在STATA中,您得到# (* p<0.05, ** p<0.01, *** p< 0.001)
。
这意味着R结果中带*的显着性对于STATA用户而言似乎并不重要。