2

我正在使用AUC 包在 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"

示例仅包括基本功能,不演示使用截止、tpr 或 fpr。

我不知道如何将截止值合并到 roc 函数中。以前有人在 AUC 包中使用过截止值吗?我知道它可以用其他包来完成,但如果可能的话,我想坚持使用这个包,因为我的数据和代码已经为它设置好了。

4

1 回答 1

1

听起来您想计算与指定概率截止值相对应的真阳性率 (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。

于 2016-02-24T03:34:03.353 回答