How to extract the p-value for the slope from an ols object in R

强颜欢笑 提交于 2019-12-12 16:49:23

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!