Skip to content
Prev 82513 / 398506 Next

retrieving p-values in lm

On Fri, 2005-12-09 at 14:19 +0100, Patrick Kuss wrote:
First, you might want to review Chapter 11: Statistical Models in R in
An Introduction to R, which is available with your R installation or
from the main R web site under Documentation. Specifically, page 53
describes the extractor functions to be used for getting model
information.

In this case using coef() will extract the model coefficients in both
cases:
Estimate   Std. Error  t value   Pr(>|t|)
(Intercept) 6.245371e-02 4.713400e-02 1.325024 0.20173833
alt         6.179038e-05 2.261665e-05 2.732074 0.01368545
Estimate   Std. Error    t value  Pr(>|t|)
(Intercept) -9.433748e-02 3.133627e-01 -0.3010488 0.7670283
alt          2.178857e-04 3.091330e-04  0.7048283 0.4904618
I(alt^2)    -3.838002e-08 7.579576e-08 -0.5063610 0.6191070


In both models, the coefficients are present if you review the structure
as you have in your code above:
[1] "call"          "terms"         "residuals"     "coefficients" 
 [5] "aliased"       "sigma"         "df"            "r.squared"    
 [9] "adj.r.squared" "fstatistic"    "cov.unscaled"
[1] "call"          "terms"         "residuals"     "coefficients" 
 [5] "aliased"       "sigma"         "df"            "r.squared"    
 [9] "adj.r.squared" "fstatistic"    "cov.unscaled" 


So, you can get the term p values by using:
(Intercept)         alt 
 0.20173833  0.01368545
(Intercept)         alt    I(alt^2) 
  0.7670283   0.4904618   0.6191070 


In terms of the overall model p value, this is actually calculated when
you display (print) the model. It is not stored as part of the model
object itself. If you review the code for print.summary.lm() using:
...
   pf(x$fstatistic[1], x$fstatistic[2], x$fstatistic[3],
      lower.tail = FALSE)
...


Where the first argument is the F statistic and the other two are the
degrees of freedom:
value     numdf     dendf 
 7.464231  1.000000 18.000000
value     numdf     dendf 
 3.706139  2.000000 17.000000 


So, in the case of your two models:
lower.tail = FALSE)
     value 
0.01368545
lower.tail = FALSE)
    value 
0.0461472 


HTH,

Marc Schwartz