【问题标题】:Extract only coefficients whose p values are significant from a logistic model从逻辑模型中仅提取 p 值显着的系数
【发布时间】:2013-04-10 20:35:30
【问题描述】:

我已经运行了一个逻辑回归,我对其进行了总结。 “得分”因此,summary(score) 给了我以下信息

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-1.3616  -0.9806  -0.7876   1.2563   1.9246  

                       Estimate Std. Error    z value    Pr(>|z|)
(Intercept)        -4.188286233 1.94605597 -2.1521921 0.031382230 *
Overall            -0.013407201 0.06158168 -0.2177141 0.827651866
RTN                -0.052959314 0.05015013 -1.0560154 0.290961160
Recorded            0.162863294 0.07290053  2.2340482 0.025479900 *
PV                 -0.086743611 0.02950620 -2.9398438 0.003283778 **
Expire             -0.035046322 0.04577103 -0.7656878 0.443862068
Trial               0.007220173 0.03294419  0.2191637 0.826522498
Fitness             0.056135418 0.03114687  1.8022810 0.071501212 .

---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for binomial family taken to be 1)

    Null deviance: 757.25  on 572  degrees of freedom
Residual deviance: 725.66  on 565  degrees of freedom
AIC: 741.66

Number of Fisher Scoring iterations: 4

我希望实现的是获取变量名称和这些变量的系数,这些变量的 Pr(>|z|) 值旁边有 ******。换句话说,我希望上述变量和系数具有Pr(>|z|)

理想情况下,我希望将它们放入数据框中。不幸的是,我尝试过的以下代码不起作用。

variable_try <-
  summary(score)$coefficients[if(summary(score)$coefficients[, 4] <= .05, 
                                 summary(score)$coefficients[, 1]),]

Error: unexpected ',' in "variable_try <-
summary(score)$coefficients[if(summary(score)$coefficients[,4] < .05,"

【问题讨论】:

    标签: r extract regression


    【解决方案1】:

    这个呢:

    data.frame(summary(score)$coef[summary(score)$coef[,4] <= .05, 4])
    

    【讨论】:

    • @JonathanRossCharlton 重新命名问题;请不要那样做。对任何人有什么用?
    • @JonathanRossCharlton 除非用户明确声明他们投了反对票,否则您无法知道是谁投的票。投票是完全匿名的。无论如何,诸如“R 编程”之类的内容和提及特定用户在标题中被认为是不恰当的。
    • 嘿,乔兰 - 我很喜欢这个建议。关于投票,可能没有办法知道,但可能有一种计算方式。我认为我们是对应的,我看到投票结果是-1。所以我算了。同样,我也赞成 Gavin 的建议,我也会赞成你的建议。无意破坏规则;因此,应注意。
    • @tcash21,如果你有因素怎么办?你不会得到真名,而是名字+等级。你怎么能克服这个?谢谢。
    • @GavinSimpson 如果 x 是上面的 data.frame:stringr::str_match(rownames(x), "\\((.*)\\)")[,2]
    猜你喜欢
    • 1970-01-01
    • 2022-06-15
    • 1970-01-01
    • 1970-01-01
    • 2018-05-10
    • 1970-01-01
    • 2020-12-22
    • 1970-01-01
    • 2018-05-04
    相关资源
    最近更新 更多