list 从 R 中的 glm 中提取系数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4780152/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
extract coefficients from glm in R
提问by lokheart
I have performed a logistic regression with the following result:
我进行了逻辑回归,结果如下:
ssi.logit.single.age["coefficients"]
# $coefficients
# (Intercept) age
# -3.425062382 0.009916508
I need to pick up the coefficient for age
, and currently I use the following code:
我需要获取 的系数age
,目前我使用以下代码:
ssi.logit.single.age["coefficients"][[1]][2]
It works, but I don't like the cryptic code here, can I use the name of the coefficient (i.e. (Intercept)
or age
)
它有效,但我不喜欢这里的神秘代码,我可以使用系数的名称吗(即(Intercept)
或age
)
回答by James
There is an extraction function called coef
to get coefficients from models:
有一个提取函数被调用coef
来从模型中获取系数:
coef(ssi.logit.single.age)["age"]
回答by lokheart
I've found it, from here
我找到了,从这里
Look at the data structure produced by summary()
看summary()产生的数据结构
> names(summary(lm.D9))
[1] "call" "terms" "residuals" "coefficients"
[5] "aliased" "sigma" "df" "r.squared"
[9] "adj.r.squared" "fstatistic" "cov.unscaled"
Now look at the data structure for the coefficients in the summary:
现在查看摘要中系数的数据结构:
> summary(lm.D9)$coefficients
Estimate Std. Error t value Pr(>|t|)
(Intercept) 5.032 0.2202177 22.850117 9.547128e-15
groupTrt -0.371 0.3114349 -1.191260 2.490232e-01
> class(summary(lm.D9)$coefficients)
[1] "matrix"
> summary(lm.D9)$coefficients[,3]
(Intercept) groupTrt
22.850117 -1.191260