Tell me more ×
Cross Validated is a question and answer site for statisticians, data analysts, data miners and data visualization experts. It's 100% free, no registration required.

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?

share|improve this question

1 Answer

up vote 2 down vote accepted

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.

share|improve this answer
Is it possible to modify this function so I can plot ROC curves for multivariate models? So far I have only been able to overlay univariate ROC curves. What I really want is to compare nested models. Thanks! – half-pass May 25 '12 at 3:51
As long as the outcome is univariate/Bernoulli then sure. Just pass a matrix or data-frame to the X argument with each column representing the predictions from a different model. So matching your above example: colAUC(X=cbind(x1,x2),y=y,plotROC=TRUE) – Shea Parkes May 25 '12 at 14:52
I read your comment again and am not sure I fully comprehended your question. I am assuming you want to compare the predictions from nested models. To do that you just want the final prediction from each model, not the individual contributions to that prediction from each feature. – Shea Parkes May 25 '12 at 14:54
Yes, I do want to compare final predictions from nested models. But when I use colAUC on the example data above, I ended up with one ROC curve for y ~ x1 and one for y ~ x2. Instead I want overlaid curves for y ~ x1 and y ~ x1 + x2. Thanks. – half-pass May 28 '12 at 0:49
You would just need to build out the columns like this then colAUC(X=data.frame(fit1=x1,fit2=x1+x2),y=y,plotROC=TRUE) – Shea Parkes May 28 '12 at 16:44
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.