Search code examples
rrocauc

AUC unexpected value


I have the following predictions after running a logistic regression model on a set of molecules we suppose that are predictive of tumors versus normals.

                  Predicted   class     
                      T        N          
                 T   29        5
  Actual class
                 N   993      912           

I have a list of scores that range from predictions <0 (negative numbers) to predictions >0 (positive numbers). Then I have another column in my data.frame that indicated the labels (1== tumours and 0==normals) as predicted from the model. I tried to calculate the ROC using the library(ROC) in the following way:

 pred = prediction(prediction, labels)     
 roc = performance(pred, "tpr", "fpr")   
 plot(roc, lwd=2, colorize=TRUE)   

Using:

       roc_full_data <- roc(labels, prediction)
       rounded_scores <- round(prediction, digits=1)
       roc_rounded <- roc(labels, prediction)

Call:

       roc.default(response = labels, predictor = prediction)
       Data: prediction in 917 controls (category 0) < 1022 cases (category1).
       Area under the curve: 1

The AUC is equal to 1. I'm not sure that I run all correctly or probably I'm doing something wrong in the interpretation of my results because it is quite rare that the AUC is equal to 1.


Solution

  • There is a typo in your x.measure which should have thrown an error. You have "for" and not "fpr". Try the following code.

    performance(pred, measure = "tpr", x.measure = "fpr")
    plot(perf)
    
    # add a reference line to the graph
    abline(a = 0, b = 1, lwd = 2, lty = 2)
    
    # calculate AUC
    perf.auc <- performance(pred, measure = "auc")
    str(perf.auc)
    as.numeric([email protected])