如何从 R 中的 ols 对象中提取斜率的 p 值 [英] How to extract the p-value for the slope from an ols object in R

查看:101
本文介绍了如何从 R 中的 ols 对象中提取斜率的 p 值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我这样做

data(mtcars)
m1 <- lm(mpg ~ cyl, data= mtcars, x= TRUE, y= TRUE)

然后我可以使用 summary(m1)$coefficients[2, 4] 提取斜率的 p 值.

then I can extract the p-value for the slope using summary(m1)$coefficients[2, 4].

但是如果我这样做

library(rms)
data(mtcars)
m2 <- ols(mpg ~ cyl, data= mtcars, x= TRUE, y= TRUE)

我需要做什么来提取斜率的 p 值?

what do I need to do to extract the p-value for the slope?

推荐答案

可以使用对应的提取器函数,但是需要调用summary.lm:

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

这篇关于如何从 R 中的 ols 对象中提取斜率的 p 值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆