2

I would like to plot a segment of an ROC curve over a specific range of x values, instead of plotting the entire curve. I don't want to change the range of the x axis itself. I just want to plot only part of the ROC curve, within a range of x values that I specify.

library(pROC)
data(aSAH)
rocobj <- roc(aSAH$outcome, aSAH$wfns)
plot(rocobj)

That code plots the whole ROC curve. Let's say I just wanted to plot the curve from x=1 to x=.5. How could I do that? Thank you.

  • 1
    What is that you are trying to achieve by plotting that? One way is to use `1-rocobj$specificities`, `rocobj$sensitivities` – Jason Mathews Jun 19 '19 at 19:33
  • I have data that form an empirical ROC that should only extend to the minimum specificity that exists in the data. But pROC extends the ROC curve up the diagonal. I have this: [link](http://jasonfinley.com/pROCplot1.pdf) But I want it to not plot the right part. I think a variant of Dylan's solution will work. – Jason Finley Jun 20 '19 at 02:25
  • 1
    The minimum specificity that exists in any dataset is 0. You can always have a threshold at -infinity and have all negatives classified as false positives. – Calimo Jun 20 '19 at 14:32

2 Answers2

1

The plot function of pROC uses the usual R semantics for plotting, so you can use the xlim argument as you would for any other plot:

plot(rocobj, xlim = c(1, .5))
Calimo
  • 7,510
  • 4
  • 39
  • 61
  • Thank you. However, this shifts the range of the x-axis, which is not what I want to do. I still want the x-axis to display from 0 to 1. But I want only a segment of the ROC curve to be plotted. – Jason Finley Jun 20 '19 at 02:19
1

The default plot function for roc objects plots the rocobj$sensitivities as a function of rocobj$specificities.

So

plot(rocobj$specificities,rocobj$sensitivities,type="l",xlim=c(1.5,-0.5))
abline(1,-1)

achieves the same as

plot(rocobj)

And

plot(rocobj$specificities[2:6],rocobj$sensitivities[2:6],type="l",xlim=c(1.5,-0.5),ylim=c(0,1))
abline(1,-1)

Gets close to what I think you are after (plots from 0.514 to 1.0). I don't know enough about the package to know if the sensitivities can be calculated at a specific range, or resolution of specificities.

Dylan I
  • 138
  • 1
  • 8
  • Thank you! Some variant of this approach should end up working. However, with xlim=c(1,0). Directly plotting the specificities and sensitivities themselves was the breakthrough; I can choose just part of those lists to use, as you suggested. – Jason Finley Jun 20 '19 at 02:31