Ben - 11 months ago 49

R Question

Why does

`pROC`

`ROCR`

`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 Source

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
```