How to make turn ROC - AUC reversed in R?

Asked

Viewed 2,121 times

2

Good night

I need help making the ROC turn on the R.

I’m using the following command:

library(ROCR)

pred <- prediction(predictions = banco$ic, labels = banco$SM)

perf <- performance(pred, measure = "tpr", x.measure = "fpr")

plot(perf, main = "ic", col = "blue", lwd = 3)

abline(a = 0, b = 1, lwd = 2, lty = 2)

perf.auc <- performance(pred, measure = "auc")

unlist([email protected])

The variable "ic" is continuous, and means conicity index. The variable MS is categorical (binary), and means metabolic syndrome (0 - without MS; 1 - with MS).

I made the curve with these variables in SPSS and it is above the diagonal line with AUC = 0.7519.

I also did it in R, with the same variables, but the curve is below the diagonal line with AUC = 0.2481. This AUC value you gave in R is complementary to what you gave in SPSS.

In SPSS I know that it is necessary to identify the state of the variable (it was placed 1, because 1 represents the patients) and in options it is necessary to identify the direction (the option marked was "a result of the smaller test indicates a test more positive").

However, in R I do not know which command should be used to identify the direction, as should be done in SPSS. I also tested the curve in R with 0 = with SM and 1 = without SM, and gave the same thing.

Could someone tell me which command should I use on the R so that the curve is equal to the SPSS? , that is, so that the AUC curve on the R is reversed!!

  • Kaluce, welcome to Soft. You missed highlighting your code. To learn about these and other details go to Help and take the Tour.

  • 1

    Kaluce, please provide some of the data so that we can reproduce the code, and if possible graph images as you would like it to be.

  • 2

    @Leo I think you mean welcome to the sopt correct? SOPT is an abbreviation of the site name.

  • Kkkkkkk. Ok, I got carried away.... I’ll keep an eye out from now on...

  • Look, I can’t test the codes now, but this AUC value you got in R is not valid, the AUC calculation should "reverse" if it is less than 0.5, that is, if you calculate an AUC of 0.2, the correct one would be 0.8.

  • Thank you for your comments. Follow the Dropbox link with the excel data and also the image of how the curve was obtained in SPSS and R. Note that it is the same curve, but in R it is inverted. I’d like to know which command I should use on the R to get the same SPSS curve. https://www.dropbox.com/sh/wckj626n50q7n0h/AAAzHSVnUbMlSBmkby2zetSaa?dl=0

Show 1 more comment

1 answer

2

With Dropbox data and original code the chart is normal.

inserir a descrição da imagem aqui

> unlist([email protected])
[1] 0.7518116
  • Thank you for the answer. I tested it again and it worked. I thought it was strange because it hadn’t really worked before. It must have been something strange from the system, I don’t know...

  • Guys, I’m having the same problem getting the ROC curve on the R again. The ROC curve in R is below the diagonal line with AUC = 0.2481. I did not make any change in the code used. The database is continued on the Dropbox link (https://www.dropbox.com/sh/wckj626n50q7n0h/AAAzHSVnUbMlSBmkby2zetSaa?dl=0). I’m using version 3.3.1 of R, version 2.2-5 of Rcmdr and version 10 of Windows 2015. Can anyone help me understand what’s going on?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.