简体   繁体   English

使用 ROCit 绘制多条 ROC 曲线

[英]Plot multiple ROC curves using ROCit

I wanted to use ROCit for creating ROC curves.我想使用 ROCit 来创建 ROC 曲线。 But I can not figure out, how to plot two ROC curves in the same plot.但我想不通,如何在同一个图中绘制两条 ROC 曲线。

For example:例如:

data("Diabetes")
library(ROCit)
plot(rocit(score = Diabetes$chol, class = Diabetes$dtest, negref = "-"))
par(new=TRUE)
plot(rocit(score = Diabetes$bmi, class = Diabetes$dtest, negref = "-"))

Using the par command in between, I can get it to work, but I would had to set the colors all manually and also the legend does not correctly reflect the data.使用两者之间的par命令,我可以让它工作,但我必须手动设置颜色,而且图例也不能正确反映数据。

Is it somehow possible to use ROCit to compare different models in the same plot?是否可以使用 ROCit 来比较同一图中的不同模型?

You plot the first ROCit object, then add lines for subsequent ones.您绘制第一个 ROCit 对象,然后为后续对象添加线条。

Note that the subsequent ones are specified as $TPR ~ $FPR (for some reason).请注意,后续的指定为 $TPR ~ $FPR (出于某种原因)。

data(Diabetes)
library(ROCit)

# ROCit objects
roc_emp1 <- rocit(score = Diabetes$chol, class = Diabetes$dtest, negref = "-") 
roc_emp2 <- rocit(score = Diabetes$bmi, class = Diabetes$dtest, negref = "-") 

# plot the first, then the second, then add the legend
plot(roc_emp1, col = c(1,"gray50"), 
     legend = FALSE, YIndex = FALSE)
lines(roc_emp2$TPR ~ roc_emp2$FPR, 
      col = 2, lwd = 2)
legend("bottomright", col = c(1,2),
       c("Empirical ROC 1", "Empirical ROC 2"), lwd = 2)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM