从 pROC 包计算 AUC 值时出现 R 错误

R error in calculating AUC value from pROC package

我正在尝试使用 R 中的 pROC 包来计算灵敏度、特异性和阈值水平。这是一个示例数据

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')"

谁能告诉我为什么会出现此错误以及如何解决?

谢谢

这是我最好的猜测:roc 函数名称在几个包中使用(目前 CRAN 上有 11 个 according to the sos package),如果它们优先于 pROC稍后在您的会话中加载。通过重新启动 R,您从搜索路径中清除了该函数并返回使用 pROC 的 roc.

为确保您使用的是 pROC 的 roc 函数,请使用以下语法:

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