从逻辑回归中提取概率和 SE

Extract Probability and SE from Logistic Regression

我有一个任务选择数据集(1 或 0)给定变量 x。以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。环顾四周,只是变得更加困惑,所以任何帮助将不胜感激!

最佳,

好的,所以我在跟随 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]])