如何生成阳性预测值 (PPV) 与各种分类截止点的关系图?
How can I generate a plot of positive predictive value (PPV) vs various cut-off points for classifications?
我生成了一些分数来帮助预测某件事是 (1) 还是否 (0),假设数据包括:
scores = c(10:20)
response = c(0,0,1,0,1,0,1,1,0,1,1)
mydata = data.frame(scores, response)
我可以进行 ROC 分析,其 AUC 为 .77:
roc(response = mydata$response, predictor = mydata$scores)
现在,我如何准确地看到选择各种截止值时会发生什么?我想在 x 轴上设置截止值(比如 13、14、15、16、17),在 y 轴上设置 PPV。这样做的好方法是什么?我需要什么 functions/packages?
我会根据pROC包给出答案*。使用 ROCR 包也可以获得类似的结果。
您想要使用 coords
函数,它可以在某些给定的阈值下计算几个常见的统计信息。例如,为了获得所有阈值的 PPV,您可以执行以下操作:
library(pROC)
r <- roc(response = response, predictor = scores)
coordinates <- coords(r, x = "all", input = "threshold", ret = c("threshold", "ppv"))
然后您可以绘制这些值:
plot(t(coordinates))
用感兴趣的阈值替换"all"
:
coordinates <- coords(r, x = c(13, 14, 15, 16, 17), input = "threshold", ret = c("threshold", "ppv"))
* 免责声明:我是 pROC 包的作者。
我生成了一些分数来帮助预测某件事是 (1) 还是否 (0),假设数据包括:
scores = c(10:20)
response = c(0,0,1,0,1,0,1,1,0,1,1)
mydata = data.frame(scores, response)
我可以进行 ROC 分析,其 AUC 为 .77:
roc(response = mydata$response, predictor = mydata$scores)
现在,我如何准确地看到选择各种截止值时会发生什么?我想在 x 轴上设置截止值(比如 13、14、15、16、17),在 y 轴上设置 PPV。这样做的好方法是什么?我需要什么 functions/packages?
我会根据pROC包给出答案*。使用 ROCR 包也可以获得类似的结果。
您想要使用 coords
函数,它可以在某些给定的阈值下计算几个常见的统计信息。例如,为了获得所有阈值的 PPV,您可以执行以下操作:
library(pROC)
r <- roc(response = response, predictor = scores)
coordinates <- coords(r, x = "all", input = "threshold", ret = c("threshold", "ppv"))
然后您可以绘制这些值:
plot(t(coordinates))
用感兴趣的阈值替换"all"
:
coordinates <- coords(r, x = c(13, 14, 15, 16, 17), input = "threshold", ret = c("threshold", "ppv"))
* 免责声明:我是 pROC 包的作者。