Confidence interval for Roc curve in R

825 Views Asked by At

I have created the code for displaying a confidence interval for the ROC curve for both Logistic and Random Forest. But I would like to have 1- specificity in the x-axis instead of specificity. The code is

roc.list <- roc(test_df$extry ~ Logistic_Regression+Random_Forest)
ci.list <- lapply(roc.list, ci.se, specificities = seq(0, 1, l = 10))

dat.ci.list <- lapply(ci.list, function(ciobj) 
  data.frame(x = as.numeric(rownames(ciobj)),
             lower = ciobj[, 1],
             upper = ciobj[, 3]))

p <- ggroc(roc.list,legacy.axes=TRUE) + theme_minimal() + geom_abline(slope=1, intercept = 1, linetype = "dashed", alpha=0.7, color = "grey") + coord_equal()

for(i in 1:3) {
  p <- p + geom_ribbon(
    data = dat.ci.list[[i]],
    aes(x = x, ymin = lower, ymax = upper),
    fill = i + 1,
    alpha = 0.2,
    inherit.aes = F) 
} 

p

And the output: ThE CI is weird. Any idea?

1

There are 1 best solutions below

0
Calimo On

I assume you are using the ggroc function from the pROC package.

When you run ggroc with legacy.axes=TRUE, the ggplot function is called with the following aesthetics:

aes(x = "1-specificity", y = "sensitivity")

As identified by @Allan Cameron in the comments, you need to specify compatible aesthetics that specify 1-specificity in x:

p <- p + geom_ribbon(
     data = dat.ci.list[[i]],
     aes(x = 1 - x, ymin = lower, ymax = upper),
     fill = i + 1,
     alpha = 0.2,
     inherit.aes = F)