0

I can get significant coefficients while using the summary command. Here I see that Sepal.Width and Petal.Length have alot lower P values by looking at the stars. However these stars disappear if I only print out the coefficients. How do I get the stars back? (Note: I want the stars in my output.)

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

Here I try to just print out the coefficients. My significant stars are gone.

 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
Bobe Kryant
  • 2,050
  • 4
  • 19
  • 32
  • Some inspiration: [Extract only coefficients whose p values are significant from a logistic model](http://stackoverflow.com/questions/16070926/extract-only-coefficients-whose-p-values-are-significant-from-a-logistic-model) –  Feb 15 '16 at 06:21
  • @Pascal Thank you for the link. However, I want all my outputs, I just want stars next to them. I am looking through the source code, I just don't exactly see why the stars go away. – Bobe Kryant Feb 15 '16 at 06:35
  • Stars are displayed in the `print` method of the _summary_ object. When you use `coef`, it's a whole other beast. Under the summary, stars (and dots) are explained. It's easy to recreate them, but the question is - why? You have exact p-values. As good as it gets. – Roman Luštrik Feb 15 '16 at 20:34
  • You may want to have a look at the package `pixiedust` to format output. The page on GitHub has an example with asterisks which might accomodate what you are looking for: https://github.com/nutterb/pixiedust – Helix123 Feb 16 '16 at 15:31

1 Answers1

1

You can add stars in the summary data.frame. Below code does that:

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
Kumar Manglam
  • 2,780
  • 1
  • 19
  • 28
  • I expect that in the print method for `summary(plmModel)`, stars have been added. Please upvote if my soultion helps you. :) – Kumar Manglam Feb 15 '16 at 06:49