问题
If I do
data(mtcars)
m1 <- lm(mpg ~ cyl, data= mtcars, x= TRUE, y= TRUE)
then I can extract the p-value for the slope using summary(m1)$coefficients[2, 4]
.
But if I do
library(rms)
data(mtcars)
m2 <- ols(mpg ~ cyl, data= mtcars, x= TRUE, y= TRUE)
what do I need to do to extract the p-value for the slope?
回答1:
You can use the corresponding extractor function, but you need to call summary.lm
:
> coef(summary.lm(m2))
Estimate Std. Error t value Pr(>|t|)
Intercept 37.88458 2.0738436 18.267808 8.369155e-18
cyl -2.87579 0.3224089 -8.919699 6.112687e-10
来源:https://stackoverflow.com/questions/9279931/how-to-extract-the-p-value-for-the-slope-from-an-ols-object-in-r