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

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

作者: liang_rujiang | 来源:发表于2020-06-26 23:20 被阅读0次

    目的:如题

    计算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)
    

    相关文章

      网友评论

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

          本文链接:https://www.haomeiwen.com/subject/kgupfktx.html