0

Is there a way to only print the p-values of linear models in R? I only need the p-value of the global model, NOT of the coefficients.

How to only print (adjusted) R-squared of regression model? In this post is the solution for only printing the adj. r².

I tried summary(model)$p.value but it is not working.

M.m.mm
  • 27
  • 1
  • 5
  • This may be useful: https://stackoverflow.com/questions/5587676/pull-out-p-values-and-r-squared-from-a-linear-regression – Aziz Jun 16 '20 at 16:34

1 Answers1

2

The easiest way is to use the broom package:

library(broom)
# coefficient p values
tidy(model)$p.value

# model p value
glance(model)$p.value

Staying in base, you can use

# coefficient p values
summary(model)$coefficients[, "Pr(>|t|)"]

In base, you can't get the model p-value directly out of the summary - it's calculated on the fly by the print.summary.lm method. You could replicate this calculation with

with(summary(model), 
  pf(
    fstatistic[1L], 
    fstatistic[2L],
    fstatistic[3L],
    lower.tail = FALSE
  )
)
Gregor Thomas
  • 136,190
  • 20
  • 167
  • 294
  • Thank you very much. This gives the p-values of each coefficient. I only need the p-value of the global model. Is there a way to do that as well? – M.m.mm Jun 16 '20 at 16:31