Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I generate a plot of positive predictive value (PPV) vs various cut-off points for classifications?

I have generated some scores to help predict whether or not something is yes (1) or no (0), let's say the data consists of:

scores = c(10:20)

response = c(0,0,1,0,1,0,1,1,0,1,1)

mydata = data.frame(scores, response)

I can do an ROC analysis, which gives an AUC of .77:

roc(response = mydata$response, predictor = mydata$scores) 

Now, how exactly do I see what happens when various cut-offs are chosen? I'd like to have cut-offs on the x-axis (let's say 13,14,15,16,17) and PPV on the y-axis. What's a nice way of doing this? What functions/packages do I need?

like image 831
CineyEveryday Avatar asked Jan 30 '26 12:01

CineyEveryday


1 Answers

I will give an answer based around the pROC package*. It is possible to obtain similar results using the ROCR package as well.

You want to use the coords function, which can compute several common statistics at some given thresholds. For instance, in order to get the PPV at all thresholds, you can do the following:

library(pROC)
r <- roc(response = response, predictor = scores)
coordinates <- coords(r, x = "all", input = "threshold", ret = c("threshold", "ppv"))

You can then plot those values:

plot(t(coordinates))

Replace "all" by the thresholds of interest:

 coordinates <- coords(r, x = c(13, 14, 15, 16, 17), input = "threshold", ret = c("threshold", "ppv"))

* Disclaimer: I am the author of the pROC package.

like image 70
Calimo Avatar answered Feb 02 '26 03:02

Calimo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!