Tools for visualizing, smoothing and comparing receiver operating characteristic (ROC curves). (Partial) area under the curve (AUC) can be compared with statistical tests based on U-statistics or bootstrap. Confidence intervals can be computed for (p)AUC or ROC curves.
An R package to display and analyze ROC curves.
For more information, see:
The latest stable version is best installed from the CRAN:
install.packages("pROC")
Once the library is loaded with library(pROC)
, you can get help on pROC by typing ?pROC
.
If you don't want to read the manual first, try the following:
library(pROC)data(aSAH)
roc(aSAH$outcome, aSAH$s100b)roc(outcome ~ s100b, aSAH)
roc(outcome ~ s100b, aSAH, smooth=TRUE)
roc1 <- roc(aSAH$outcome, aSAH$s100b, percent=TRUE, # arguments for auc partial.auc=c(100, 90), partial.auc.correct=TRUE, partial.auc.focus="sens", # arguments for ci ci=TRUE, boot.n=100, ci.alpha=0.9, stratified=FALSE, # arguments for plot plot=TRUE, auc.polygon=TRUE, max.auc.polygon=TRUE, grid=TRUE, print.auc=TRUE, show.thres=TRUE) # Add to an existing plot. Beware of 'percent' specification! roc2 <- roc(aSAH$outcome, aSAH$wfns, plot=TRUE, add=TRUE, percent=roc1$percent)
coords(roc1, "best", ret=c("threshold", "specificity", "1-npv"))coords(roc2, "local maximas", ret=c("threshold", "sens", "spec", "ppv", "npv"))
# Of the AUCci(roc2) # Of the curvesens.ci <- ci.se(roc1, specificities=seq(0, 100, 5))plot(sens.ci, type="shape", col="lightblue")plot(sens.ci, type="bars") # need to re-add roc2 over the shapeplot(roc2, add=TRUE) # CI of thresholdsplot(ci.thresholds(roc2))
# Test on the whole AUC roc.test(roc1, roc2, reuse.auc=FALSE) # Test on a portion of the whole AUC roc.test(roc1, roc2, reuse.auc=FALSE, partial.auc=c(100, 90), partial.auc.focus="se", partial.auc.correct=TRUE) # With modified bootstrap parameters roc.test(roc1, roc2, reuse.auc=FALSE, partial.auc=c(100, 90), partial.auc.correct=TRUE, boot.n=1000, boot.stratified=FALSE)
# Two ROC curves power.roc.test(roc1, roc2, reuse.auc=FALSE) power.roc.test(roc1, roc2, power=0.9, reuse.auc=FALSE) # One ROC curve power.roc.test(auc=0.8, ncases=41, ncontrols=72) power.roc.test(auc=0.8, power=0.9) power.roc.test(auc=0.8, ncases=41, ncontrols=72, sig.level=0.01) power.roc.test(ncases=41, ncontrols=72, power=0.9)
Download the source code from git, unzip it if necessary, and then type R CMD INSTALL pROC
. Alternatively, you can use the devtools package by Hadley Wickham to automate the process (make sure you follow the full instructions to get started):
if (! requireNamespace("devtools")) install.packages("devtools")devtools::install_github("xrobin/pROC")
To run all automated tests, including slow tests:
cd .. # Run from parent directory
VERSION=$(grep Version pROC/DESCRIPTION | sed "s/.\+ //")
R CMD build pROC
RUN_SLOW_TESTS=true R CMD check pROC_$VERSION.tar.gz
The vdiffr package is used for visual tests of plots.
To run all the test cases (incl. slow ones) from the command line:
run_slow_tests <- TRUEvdiffr::manage_cases()
To run the checks upon R CMD check, set environment variable NOT_CRAN=1
:
NOT_CRAN=1 RUN_SLOW_TESTS=true R CMD check pROC_$VERSION.tar.gz
VERSION=$(grep Version pROC/DESCRIPTION | sed "s/.\+ //") && echo $VERSION
R CMD build pROC && R CMD check --as-cran pROC_$VERSION.tar.gz
NOT_CRAN=1 RUN_SLOW_TESTS=true R CMD check pROC_$VERSION.tar.gz
rhub::check_with_rdevel()
devtools::revdep_check(libpath = rappdirs::user_cache_dir("revdep_lib"), srcpath = rappdirs::user_cache_dir("revdep_src"))
Version
and Date
in DESCRIPTION
NEWS
git tag v$VERSION
1.14.0 (2019-03-12)
1.13.0 (2018-09-23)
1.12.1 (2018-05-06)
1.12.0 (2018-05-05)
1.11.0 (2018-03-24)
1.10.0 (2017-06-10)
1.9.1 (2017-02-05)
1.8 (2015-05-04)
1.7.3 (2014-06-14)
1.7.2 (2014-04-05)
1.7.1 (2014-02-20)
1.7 (2014-02-19)
1.6.0.1 (2013-12-28)
1.6 (2013-12-26)
1.5.4 (2012-08-31)
1.5.3 (2012-08-31)
1.5.1 (2012-03-09)
1.5 (2011-12-11)
1.4.4 (2011-08-09)
1.4.3 (2011-03-17)
1.4.2 (2011-03-03)
1.4.1 (2011-01-27)
1.4 (2011-01-21)
1.3.2 (2010-08-24)
1.3.1 (2010-08-18)
1.3 (2010-08-13)
1.2.1 (2010-05-11)
1.2 (2010-05-09)
1.1 (2010-05-05)
1.0.1 (2010-04-28)
1.0 (2010-04-27)