R语言基于ROCR包绘制roc曲线及相关常用检验_26Jun2020

目的:如题

计算roc曲线下面积及95%CI

# set up
library(tidyverse)
library(ROCR)

# auc & 95%CI
roc(all_sample_model[[1]]$factual, all_sample_model[[1]]$prediction, ci = T)
roc(controlled_model[[1]]$factual, controlled_model[[1]]$prediction, ci = T)
roc(not_controlled_model[[1]]$factual ,not_controlled_model[[1]]$prediction, ci = T)

绘制多条roc曲线在一幅图

# creat roc objects
roc_all <- roc(all_sample_model[[1]]$factual, all_sample_model[[1]]$prediction)   
roc_controlled <- roc(controlled_model[[1]]$factual, controlled_model[[1]]$prediction)  
roc_uncontrolled <- roc(not_controlled_model[[1]]$factual ,not_controlled_model[[1]]$prediction)

# plot
plot(roc_all, col = "black", lwd = 2)
plot(roc_controlled, add = TRUE, col = "blue", lwd = 2) # add = T or F to creat mutiple lines or single line in one figure
plot.roc(roc_uncontrolled, add=TRUE, col = "red", lwd = 2)

对比两条线是否相同

roc.test(roc_all, roc_controlled)
roc.test(roc_all, roc_uncontrolled)
roc.test(roc_controlled, roc_uncontrolled)
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。