5

I want to create a roc object by using the function 'roc' of pROC package in R, and plot the roc object. However, I am uncertain what the 'direction' argument does. the median predictor values of my controls is smaller than the median predictor value of the cases. so I think the correct direction should be '<'. But if I plot it with direction argument '>'. it just flipped the ROC curve across the diagonal line as a mirror image. I am wondering in this situation that, data telling you 1 thing, and the argument is coercing a different direction, what is being compared to what, and how is the comparison made? I read through the pROC manual on this function for the argument 'direction', and the explanation is very brief and unclear.

Hope to hear some of your input!

Calimo
  • 7,510
  • 4
  • 39
  • 61
layover
  • 155
  • 2
  • 6

1 Answers1

10

What the direction argument does is to determine how the negativity (or positivity) of an observation is determined.

To compute sensitivity and specificity at a threshold t, you must compare it with each of the observation o_i. With direction="<", o_i will be considered positive if o_i >= t, negative otherwise. With direction=">", o_i will be considered positive if o_i <= t, negative otherwise.

If you want to look at the source code, check out the roc.utils.perfs.all.safe function.

So when you changed the direction of your ROC curve, you essentially reversed all the positive and negative predictions, which is equivalent to reversing the ROC curve.

Calimo
  • 7,510
  • 4
  • 39
  • 61
  • Hello! thank you for your explanation. I have to think about it what it means for my simulation setup. will post more follow-up questions if I need further help. – layover Aug 03 '15 at 02:58
  • @layover Please remember to upvote/accept the answer if you found it useful/correct. – Calimo Aug 03 '15 at 08:34
  • Hello, when you say o_i is positive, does it mean that it is the case (response = 1) ? I used 2 levels 0 and 1, case is 1 and control is 0. – layover Aug 05 '15 at 20:32
  • Hello Calimo, I read through the source code, and I understand now. Thank you so much! – layover Aug 06 '15 at 00:07
  • @layover "`o_i` is positive" means that your predictor says the observation is positive, regardless whether it is a control or a case. If it a case, then you have a "true positive", if it was a control you have a "false positive". – Calimo Aug 06 '15 at 07:42