user53020 user53020 - 22 days ago 8
R Question

R error in calculating AUC value from pROC package

I am trying to use the

pROC
package in R to calculate sensitivity, specificity and threshold level. Here is a sample data

library(pROC)
x<-sample(0:1,7974,replace=T)
y<-sample(0:16049.2,7974,replace=T)
myroc<-roc(x,y)
coords(myroc, "best", ret=c("threshold", "sensitivity", "specificity"))

Error in UseMethod("coords") :
no applicable method for 'coords' applied to an object of class "c('double', 'numeric')"


Will anyone be able to tell me why this error is happening and how to fix it?

Thank you

Answer

Here is my best guess: the roc function name is used in several packages (11 on CRAN at the moment according to the sos package) and those will take precedence over pROC if they are loaded later in your session. By restarting R you cleared that function from your search path and are back to using pROC's roc.

To ensure you are using pROC's roc function, use the following syntax:

myroc<-pROC::roc(x,y)
Comments