【发布时间】:2018-08-30 17:17:21
【问题描述】:
fit <- lm(R1 ~ R2)
产量...
Call:
lm(formula = R1 ~ R2)
Residuals:
Min 1Q Median 3Q Max
-0.128139 -0.016528 0.000349 0.017806 0.125109
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.003785 0.001884 2.009 0.0453 *
R.2 0.949923 0.043904 21.636 <2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
我对这些结果进行了线性回归。现在我想收集一个值,更准确地说:fit["coefficients" -> "(Intercept)"]。
我试试
fit["coefficients"]
产生
$coefficients
(Intercept) R2
0.003785144 0.949923219
如何提取这个 1 值?
提前谢谢你!
【问题讨论】:
-
试试这个:
fit$coefficients[[1]]或summary(fit)$coef[1,1]。 -
成功了!谢谢!!!
-
fit$coefficients[1]也可以工作,尽管结果会被命名。您还可以使用递归索引fit[[c("coefficients", "(intercept)")]]。 -
@lmo 第二个例子应该是 ..."(Intercept)" .... 很抱歉分叉
标签: r