Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compute Youden index from two density plot

I need help with calculating the Youden index in a two density plot in R. Basically, I need to calculate the value where two density plots are overlapping The variables are numeric.

Is there any method for calculating this value (Youden index) ???

like image 472
J.R. Avatar asked Apr 09 '26 12:04

J.R.


1 Answers

We could expand this solution to get the coordinates (i.e. the y, too) for the intersection point.

Accordingly, first the two distributions are to be combined and indexed and the minimum and maximum calculated to make them comparable.

Second, use density to compute the kernel density estimates for each distribution.

The coordinates we can get with which(diff((d2$y - d1$y) > 0) != 0) + 1 for x and y as shown below.

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

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")

enter image description here

like image 153
jay.sf Avatar answered Apr 11 '26 03:04

jay.sf



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!