美文网首页
R package pROC

R package pROC

作者: 翠湖心影 | 来源:发表于2020-02-13 05:41 被阅读0次

    if(!require(pROC)) install.packages("pROC")

    test data

    data(aSAH)
    if(!require(DT)) install.packages(DT)
    DT::datatable(aSAH)

    image.png

    Example 1

     plot.roc(aSAH$outcome, aSAH$s100b,          # data
             percent = TRUE,                    # show all values in percent
             partial.auc=c(100, 90), 
             partial.auc.correct=TRUE,          # define a partial AUC (pAUC)
             print.auc=TRUE,                    
             #display pAUC value on the plot with following options:
             print.auc.pattern = "Corrected pAUC (100-90%% SP):\n%.1f%%",
             print.auc.col = "#1c61b6",
             auc.polygon = TRUE, 
             auc.polygon.col = "#1c61b6",       # show pAUC as a polygon
             max.auc.polygon = TRUE, 
             max.auc.polygon.col = "#1c61b622", # also show the 100% polygon
             main = "Partial AUC (pAUC)")
    plot.roc(aSAH$outcome, aSAH$s100b,
             percent = TRUE, 
             add = TRUE, 
             type = "n",                        # add to plot, but don't re-add the ROC itself (useless)
             partial.auc = c(100, 90), 
             partial.auc.correct = TRUE,
             partial.auc.focus = "se",          # focus pAUC on the sensitivity
             print.auc = TRUE, 
             print.auc.pattern = "Corrected pAUC (100-90%% SE):\n%.1f%%", 
             print.auc.col = "#008600",
             print.auc.y = 40,                  # do not print auc over the previous one
             auc.polygon = TRUE, 
             auc.polygon.col = "#008600",
             max.auc.polygon = TRUE, 
             max.auc.polygon.col = "#00860022")
    
    image.png

    Example 2

     rocobj <- plot.roc(aSAH$outcome, aSAH$s100b,
                       main = "Confidence intervals", 
                       percent=TRUE,
                       ci = TRUE,                  # compute AUC (of AUC by default)
                       print.auc = TRUE)           # print the AUC (will contain the CI)
    ciobj <- ci.se(rocobj,                         # CI of sensitivity
                   specificities = seq(0, 100, 5)) # over a select set of specificities
    plot(ciobj, type = "shape", col = "#1c61b6AA")     # plot as a blue shape
    plot(ci(rocobj, of = "thresholds", thresholds = "best")) # add one threshold
    
    image.png

    Example 3

    data(aSAH)
    rocobj1 <- plot.roc(aSAH$outcome, aSAH$s100,
                        main="Statistical comparison",
                        percent=TRUE,
                        col="#1c61b6")
    rocobj2 <- lines.roc(aSAH$outcome, aSAH$ndka, 
                         percent=TRUE, 
                         col="#008600")
    testobj <- roc.test(rocobj1, rocobj2)
    text(50, 50, labels=paste("p-value =", format.pval(testobj$p.value)), adj=c(0, .5))
    legend("bottomright", legend=c("S100B", "NDKA"), col=c("#1c61b6", "#008600"), lwd=2)
    
    image.png

    相关文章

      网友评论

          本文标题:R package pROC

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