Ben Ben - 2 months ago 7
R Question

Unexpected AUC ROC result using pROC

Why does

pROC
give 0.833 in the following example, while
ROCR
gives 0.75 (which is what I'd expect)?

library(data.table)
library(pROC)
library(ROCR)

# Data
dt <- data.table(Pred=c(.5, .5, .5, 1), Outcome=c(1,0,0,1))

# Evaluation metrics
roc(dt$Pred, dt$Outcome)$auc # 0.833
performance(prediction(dt$Pred, dt$Outcome), measure="auc")@y.values[[1]] # 0.75

Answer

In roc function you have to switch arguments like this:

> roc( dt$Outcome,dt$Pred)

Call:
roc.default(response = dt$Outcome, predictor = dt$Pred)

Data: dt$Pred in 2 controls (dt$Outcome 0) < 2 cases (dt$Outcome 1).
Area under the curve: 0.75

or specify what argument is the response and predictor

 > roc(predictor=dt$Pred, response=dt$Outcome)

Call:
roc.default(response = dt$Outcome, predictor = dt$Pred)

Data: dt$Pred in 2 controls (dt$Outcome 0) < 2 cases (dt$Outcome 1).
Area under the curve: 0.75
Comments