使用summary命令时,我可以获得重要的系数。在这里,我看到Sepal.Width和Petal.Length通过观察星星有很多较低的P值。然而,如果我只打印出系数,这些星星会消失。我如何让星星回来? (注意:我想要输出中的星星。)
library(plm)
m1 = plm(Sepal.Length ~ Sepal.Width + Petal.Length + Petal.Width, data=iris, index=c('Species'))
summary(m1)
Oneway (individual) effect Within Model
Call:
plm(formula = Sepal.Length ~ Sepal.Width + Petal.Length + Petal.Width,
data = iris, index = c("Species"))
Balanced Panel: n=3, T=50, N=150
Residuals :
Min. 1st Qu. Median 3rd Qu. Max.
-0.79400 -0.21900 0.00899 0.20300 0.73100
Coefficients :
Estimate Std. Error t-value Pr(>|t|)
Sepal.Width 0.495889 0.086070 5.7615 4.868e-08 ***
Petal.Length 0.829244 0.068528 12.1009 < 2.2e-16 ***
Petal.Width -0.315155 0.151196 -2.0844 0.03889 *
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Total Sum of Squares: 38.956
Residual Sum of Squares: 13.556
R-Squared: 0.65201
Adj. R-Squared: 0.62593
F-statistic: 89.9338 on 3 and 144 DF, p-value: < 2.22e-16
这里我尝试打印出系数。我的重要明星消失了。
summary(m1)$coeff
Estimate Std. Error t-value Pr(>|t|)
Sepal.Width 0.4958889 0.08606992 5.761466 4.867516e-08
Petal.Length 0.8292439 0.06852765 12.100867 1.073592e-23
Petal.Width -0.3151552 0.15119575 -2.084418 3.888826e-02
答案 0 :(得分:1)
您可以在摘要data.frame中添加星标。下面的代码就是这样:
library(plm)
m1 = plm(Sepal.Length ~ Sepal.Width + Petal.Length + Petal.Width, data=iris, index=c('Species'))
summary(m1)
modelSum <- data.frame(summary(m1)$coeff)
modelSum$stars <- ' '
modelSum$stars <- ifelse( modelSum$Pr...t.. <= 0.1 & modelSum$Pr...t.. > 0.05 ,'.', modelSum$stars)
modelSum$stars <- ifelse( modelSum$Pr...t.. <= 0.05 & modelSum$Pr...t.. > 0.01 ,'*', modelSum$stars)
modelSum$stars <- ifelse( modelSum$Pr...t.. <= 0.01 & modelSum$Pr...t.. > 0.001 ,'**', modelSum$stars)
modelSum$stars <- ifelse( modelSum$Pr...t.. <= 0.001,'***', modelSum$stars)
modelSum