使用R中的AUC包更改ROC截止值

时间:2016-02-24 02:48:59

标签: r prediction roc auc

我正在使用AUC package在R中构建ROC图。

这是300点数据集的前5个点,比较存活概率与观察到的存活率。

predict1 <- c(0.755, 0.755, 0.937, 0.978, 0.755)
y <- c(1,1,1,0,1)

ROC_null_a <- auc(roc(predict1, as.factor(y)))
plot(roc(predict1, as.factor(y)))

我想更改ROC图的截止值。文档描述了这些值,但未指定如何在roc或auc函数中实际使用它们:

“值

包含以下元素的列表:

cutoffs  A numeric vector of threshold values

fpr  A numeric vector of false positive rates corresponding to the threshold values

tpr  A numeric vector of true positive rates corresponding to the threshold values"

示例仅包括基本功能,不使用cutoffs,tpr或fpr进行演示。

我很难理解如何将截止值合并到roc函数中。之前有没有人在AUC包中使用过截止值?我知道它可以用其他软件包完成,但是如果可能的话,我希望坚持使用这个软件包,因为我已经为它设置了数据和代码。

1 个答案:

答案 0 :(得分:0)

听起来你想要计算对应于指定概率截止值的真阳性率(TPR)和误报率(FPR)。考虑为您的数据计算roc对象:

library(AUC)
predict1 <- c(0.755, 0.755, 0.937, 0.978, 0.755)
y <- c(1,1,1,0,1)
r <- roc(predict1, as.factor(y))

给定截止值p(我将其设置为0.85以下),您可以使用r$cutoffs来计算输出的ROC对象中与您选择的截止值相对应的位置:

p <- 0.85
index <- max(which(r$cutoffs >= p))

最后,您可以在计算位置查找TPR和FPR:

r$tpr[index]
# [1] 0.25
r$fpr[index]
# [1] 1

在这种情况下,我们可以手动确认这个结果是正确的:1/4(25%)阳性观察值预测值为0.85或更高,证实TPR为0.25,并且1/1(100%)为阴性观察值预测值为0.85或更高,证实了FPR为1。