3
votes

I want to compare the auc of four roc curves in R. I tried roc.test , but this function can just compare two curves

roc.test(roc1,roc2)

Does R have a function to compare four curves? I know in stata I can compare 4 curves by roccomp. Does any one know how to compare four curves in R?

Thanks!!

1
I'm not familiar with Stata's roccomp function. What are looking for exactly, a table with the AUC and 95% confidence intervals, a plot, a p value (with which H0)?Calimo

1 Answers

5
votes

I don't think its there with roc.test but you can use library(caTools) to do it.

It is very easy to compare AUC values like below by using 'sapply' using library(pROC) as well, I am describing both the methods here:

Example and Setup for both the methods:

Building the model here:

    lm1 <- lm(am ~ disp + mpg, data= mtcars)
    lm2 <- lm(am ~ disp + hp, data= mtcars)
    lm3 <- lm(am ~ disp + wt, data= mtcars)

Predicting the model here:

predict1 <- predict(lm1, newdata=mtcars)
predict2 <- predict(lm2, newdata=mtcars)
predict3 <- predict(lm3, newdata=mtcars)

Method1:

library("caTools")
colAUC(cbind(predict1, predict2, predict3), mtcars$am, plotROC = T)

Output:

                 [,1]      [,2]      [,3]
    0 vs. 1 0.8380567 0.9433198 0.9433198

If you choose to use plotROC = T then you will receive a plot comparison between the ROCs

enter image description here

Method2:

auc.val <- sapply(list(predict1, predict2, predict3),function(x)roc(pred=x,resp=mtcars$am)$auc)

Finally calculating the AUC using sapply here:

library(pROC)
auc.val <- sapply(list(predict1, predict2, predict3),function(x)roc(pred=x,resp=mtcars$am)$auc)

would return this:

> auc.val
[1] 0.8380567 0.9433198 0.9433198

In case you are interested printing this with names , use USE.NAMES in sapply

> auc.val <- sapply(list("lm1" = predict1, "lm2" = predict2,"lm3"= predict3),function(x)roc(pred=x,resp=mtcars$am)$auc, USE.NAMES = T)
> auc.val
      lm1       lm2       lm3 
0.8380567 0.9433198 0.9433198