Hi 热心西红柿啰嗦两句,
pROC慢的原因是,用auc()
的时候,它调用了roc类及其下面的方法,所以你会看到算了sensitivity,specificity等一些指标。从profvis也可以看出其层层调用,这是这个包的面向对象设计的问题。有人已经提出这个issue了:https://github.com/xrobin/pROC/issues/17

ROCR很快是因为performance()
只调用了auc
方法,所以只算了AUC这个指标,代码如下:
.performance.auc <-
function(predictions, labels, cutoffs, fp, tp, fn, tn,
n.pos, n.neg, n.pos.pred, n.neg.pred, fpr.stop) {
x <- fp / n.neg
y <- tp / n.pos
finite.bool <- is.finite(x) & is.finite(y)
x <- x[ finite.bool ]
y <- y[ finite.bool ]
if (length(x) < 2) {
stop(paste("Not enough distinct predictions to compute area",
"under the ROC curve."))
}
if (fpr.stop < 1) {
ind <- max(which( x <= fpr.stop ))
tpr.stop <- approxfun( x[ind:(ind+1)], y[ind:(ind+1)] )(fpr.stop)
x <- c(x[1:ind], fpr.stop)
y <- c(y[1:ind], tpr.stop)
}
ans <- list()
auc <- 0
for (i in 2:length(x)) {
auc <- auc + 0.5 * (x[i] - x[i-1]) * (y[i] + y[i-1])
}
ans <- list( c(), auc)
names(ans) <- c("x.values","y.values")
return(ans)
}
以上。嘻嘻~