从两个密度图计算约登指数

Compute Youden index from two density plot

我需要帮助计算 R 中两个密度图中的约登指数。基本上,我需要计算两个密度图重叠的值 变量是数字。

这个值(约登指数)有什么计算方法吗???

我们可以扩展 this solution 以获得交点 .

的坐标(即 y

据此,首先将两个分布进行合并和索引,计算最小值和最大值,使它们具有可比性。

其次,使用 density 计算每个分布的核密度估计值。

我们可以用which(diff((d2$y - d1$y) > 0) != 0) + 1得到xy的坐标,如下所示。

set.seed(42)
n <- 1e3
dat <- data.frame(v=c(rnorm(n, 1, 3), rnorm(n, 5, 3)),
                  grp=rep(1:2, each=n))

lo <- min(dat$v)
up <- max(dat$v)

d1 <- density(dat$v[dat$grp == 1], from=lo, to=up, n=2^10)
d2 <- density(dat$v[dat$grp == 2], from=lo, to=up, n=2^10)

intersection.point <- cbind(x=d1$x[which(diff((d2$y - d1$y) > 0) != 0) + 1], 
                            y=d1$y[which(diff((d2$y - d1$y) > 0) != 0) + 1])

情节

plot(d1, ylim=c(0, .14), main="Intersection point")
lines(d2)
points(intersection.point, col="red", pch=19)
legend("topright", pch=19, col="red", legend="intersection point")