This is a very basic question but I don't get why the following provides different results when applying pROC or ROCR, see plot.
Exp = c(1,0,1,1,1,1,1,0,0,1)
Pred = c(63.2,110.8,55.57,34.40,34.16,53.8,76.3,76.3,94.8,61.3)
# ########################## pROC ##########################
rocobj <- roc(response = Exp, predictor = Pred)
plot.roc(rocobj,main="pROC")
# ########################## ROCR ##########################
ROCRpred<-prediction(Pred,Exp)
plot(performance(ROCRpred,'tpr','fpr'),main="ROCR")
The interpretation of 1/0 should be same, why is it not?
Another question is what if I want to use say P/N for levels? Is there an order in which I have to define them?
Best Answer
The
prediction
functionIf you do not specify which class is a positive case and a negative case then the prediction function needs to make up it's mind about positive and negative cases automatically. It does this as following:
by specifying
label.ordering = c(1,0)
likeyou will get what you want.
Note that you can find help in R by typing
help(prediction)
and when you type just the name of the functionprediction
then you can see the function itself. (and of course you can replace this for any other function)Conventions
You better use the following "conventions":
The following is a quote from the help file of the
prediction
function:So if you use
it works as well (in the sense that the curve is in the upper half, but note that there can still be a difference:
prediction(-Pred, Exp)
is not the same asprediction(Pred, -Exp)
, an image is shown later in this post).Why did
roc
work butprediction
not?The
roc
function from thepROC
package automatically determines the direction whether a higher score relates to a higher/lower probability of the positive class.You still have to be very clear about the positive cases and negative cases though. You can get different results: