首页 > 解决方案 > 如何在 ROCit 中计算 ROC?

问题描述

我想用 ROCit 来创建 ROC 曲线。我可以改变计算 ROC 曲线的方向(高值与健康有关)吗?

标签: rroc

解决方案


install.packages("ROCit")
require(ROCit)

由于问题中没有示例,我将从文档中的示例开始,?rocit如果我误解了您的问题,请告诉我。

# Load some example data
data("Diabetes")

# Calculate some ROC/validation data
roc_empirical <- rocit(score = Diabetes$chol, class = Diabetes$dtest,
                       negref = "-") # default method empirical
roc_binormal <- rocit(score = Diabetes$chol, class = Diabetes$dtest,
                      negref = "-", method = "bin")

# Summarize and plot the results 
summary(roc_empirical) #60/329
summary(roc_binormal) 
plot(roc_empirical)
plot(roc_binormal, col = c("#00BA37", "#F8766D"),
     legend = FALSE, YIndex = FALSE)

我们可以查看summary(roc_empirical)基线的输出:

 Empirical ROC curve                  
 Number of postive responses :  60    
 Number of negative responses :  329  
 Area under curve :  0.652684903748734

现在,如果我理解(?)你只是想翻转参考值的含义/方向,在这种情况下是Diabetes$dtest

我们可以使用negref参数来完成此操作:

roc_empirical <- rocit(score = Diabetes$chol, class = Diabetes$dtest,
                       negref = "+") # default method empirical
roc_binormal <- rocit(score = Diabetes$chol, class = Diabetes$dtest,
                      negref = "+", method = "bin")

summary(roc_empirical)
summary(roc_binormal) 
plot(roc_empirical)
plot(roc_binormal, col = c("#00BA37", "#F8766D"),
     legend = FALSE, YIndex = FALSE)

我们可以将结果summary(roc_empirical)与我们之前看到的结果进行比较,发现它是“翻转”的:

 Empirical ROC curve                  
 Number of postive responses :  329   
 Number of negative responses :  60   
 Area under curve :  0.353850050658561

当然,您也可以重新编码有问题的列。

这就是你所需要的吗?


推荐阅读