Plotting overlaid ROC curves

2017-10-11 00:46:14

I'm trying to make overlaid ROC curves to represent successive improvements in model performance when particular predictors are added one at a time to the model. I want one ROC curve for each of about 5 nested models (which I will define manually), all overlaid in one plot. For example:

#outcome var

y = c(rep(0,50), rep(1, 50))

#predictors

x1 = y + rnorm(100, sd = 1)

x2 = y + rnorm(100, sd = 4)

#correlations of predictors with outcome

cor(x1, y)

cor(x2, y)

library(Epi)

ROC(form = y ~ x1, plot = "ROC)

ROC(form = y ~ x1 + x2, plot = "ROC")

I'd want the two ROC curves on the same plot (and ideally without the distracting model info in the background). Any ggplot/graphics gurus willing to lend a hand?

The caTools package provides the colAUC function. Use it and set the plotROC argument to TRUE. I have been satisfied with the graphs it produces.

If you'd like to overlay the ROC curves over each other, you can use

  • The caTools package provides the colAUC function. Use it and set the plotROC argument to TRUE. I have been satisfied with the graphs it produces.

    2017-10-11 01:28:06
  • If you'd like to overlay the ROC curves over each other, you can use the roc function from the pROC R package to get the sensitivity and specificity values and plot them out manually,

    #outcome var

    y = c(rep(0,50), rep(1, 50))

    #predictors

    x1 = y + rnorm(100, sd = 1)

    x2 = y + rnorm(100, sd = 4)

    model1 = glm(y ~ x1, family = binomial())

    pred1 = predict(model1)

    model2 = glm(y ~ x1 + x2, family = binomial())

    pred2 = predict(model2)

    library(pROC)

    roc1 = roc(y, pred1)

    roc2 = roc(y, pred2)

    Specificity and Sensitivity Values

    > str(roc1)

    List of 15

    \$ percent : logi FALSE

    \$ sensitivities : num [1:101] 1 1 0.98 0.98 0.98 0.98 0.98 0.98 0.96...

    \$ specificities : num [1:101] 0 0.02 0.02 0.04 0.06 0.08 0.1 0.12 0.12

    ...

    or use the plot function as

    plot(roc1, col = 1, lty = 2, main = "ROC")

    plot(roc2, col = 4, lty = 3, add = TRUE)

    Also, there is also the pROC::ggroc function for ggplot2 plotting abilities.

    2017-10-11 01:53:56