plotting ROC in R with ROCR vs pROC plotting ROC in R with ROCR vs pROC r r

plotting ROC in R with ROCR vs pROC


To confirm, you are right in that true positive rate = sensitivity and false positive rate = 1 - specificity. In your example, the order in which you plot components of the ROCR performance object from the ROCR package is key. In the last line, the first performance measure, true positive rate, 'tpr' gets plotted on the y-axis measure = 'tpr' and the second performance measure, false positive rate, is plotted on the x-axis x.measure = 'fpr'

plot(performance(ROCRpred, measure = 'tpr', x.measure = 'fpr'))


Just to say, for the pROC package if you include the following in your plot code:

plot(roc(obs,pred), legacy.axes = TRUE)

then you end up with a reversed x-axis.


As far as I know:

TPR = sensitivity = TP/(TP/FN) -> y axis: [0, 1]FPR = 1 - specificity = 1 - (TN/(FP+TN)) -> x axis: [0, 1]

But, when the graph shows specificity (true negative rate) in the x-axis then the range is [1, 0].

In both cases, the graph is the same.

You can check it here in wikipedia page.