【问题标题】:Extract Probability and SE from Logistic Regression从逻辑回归中提取概率和 SE
【发布时间】:2018-07-01 18:43:34
【问题描述】:

在给定变量 x 的情况下,我有一个任务选择数据集(1 或 0)。以 mtcars 为例

#binomial_smooth() from https://ggplot2.tidyverse.org/reference/geom_smooth.html
binomial_smooth <- function(...) {
  geom_smooth(method = "glm", method.args = list(family = "binomial"), ...)
}

#plot
ggplot(data = mtcars, aes(x = disp, y = am)) + geom_point(alpha = 0.5) + binomial_smooth()

#create a model
model <- glm(am ~ disp, family = "binomial", data = mtcars)

其中 am 将是主题选择并显示 x 变量。我想计算二进制变量 = 0.5 的 x +/- SE 的值(我想这是 binomial_smooth 绘制的,尽管我可能是错的)。

使用 mtcars,我想找出 disp +/- SE am = 0.5。环顾四周,只是变得更加困惑,所以任何帮助将不胜感激!

最好的,

【问题讨论】:

标签: r logistic-regression prediction


【解决方案1】:

好的,所以我在追随 Roman Luštrik 的兔子洞之后才知道这一点(干杯!)。

使用 MASS 包和用于计算 LD50 的函数。还允许手动选择要查找的 p 值。

library(ggplot2)
library(MASS)
#binomial_smooth() from https://ggplot2.tidyverse.org/reference/geom_smooth.html
binomial_smooth <- function(...) {
  geom_smooth(method = "glm", method.args = list(family = "binomial"), ...)
}

#create a model
model <- glm(am ~ disp, family = "binomial", data = mtcars)

#get the 'LD50'- the point at which the binomial regression crosses 50%
LD50 <- dose.p(model, p = 0.5)

#print the details
print(LD50)

#replot the figure with the LD50 vlines
ggplot(data = mtcars, aes(x = disp, y = am)) + 
  geom_point(alpha = 0.5) + 
  binomial_smooth() +
  geom_vline(xintercept = LD50[[1]])

【讨论】:

    猜你喜欢
    • 2015-05-04
    • 2013-12-24
    • 1970-01-01
    • 2013-06-05
    • 2019-04-04
    • 2017-11-20
    • 2019-04-06
    • 2023-04-04
    • 2016-03-08
    相关资源
    最近更新 更多