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

2020-06-26  本文已影响0人  liang_rujiang

目的:如题

计算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)
上一篇下一篇

猜你喜欢

热点阅读