我正在尝试制作一个图表,以展示 logistic(或 probit)回归背后的直觉。我该如何使用 ggplot 制作类似于这样的图表?
(Wolf & Best,《回归分析和因果推断的贤者手册》,2015年,第155页)
实际上,我更希望在y轴上显示一个单一的正态分布,均值为0,具有特定的方差,这样我就可以从线性预测器到y轴和侧向正态分布画出水平线。类似于这样:
这段内容(假设我没有误解)所要展示的是 。到目前为止,我的进展不太顺利...
library(ggplot2)
x <- seq(1, 11, 1)
y <- x*0.5
x <- x - mean(x)
y <- y - mean(y)
df <- data.frame(x, y)
# Probability density function of a normal logistic distribution
pdfDeltaFun <- function(x) {
prob = (exp(x)/(1 + exp(x))^2)
return(prob)
}
# Tried switching the x and y to be able to turn the
# distribution overlay 90 degrees with coord_flip()
ggplot(df, aes(x = y, y = x)) +
geom_point() +
geom_line() +
stat_function(fun = pdfDeltaFun)+
coord_flip()