AnR package to display andanalyze ROC curves.
For more information, see:
The latest stable version is best installed from the CRAN:
install.packages("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 aucpartial.auc=c(100,90),partial.auc.correct=TRUE,partial.auc.focus="sens",# arguments for cici=TRUE,boot.n=100,ci.alpha=0.9,stratified=FALSE,# arguments for plotplot=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 AUCroc.test(roc1, roc2,reuse.auc=FALSE)# Test on a portion of the whole AUCroc.test(roc1, roc2,reuse.auc=FALSE,partial.auc=c(100,90),partial.auc.focus="se",partial.auc.correct=TRUE)# With modified bootstrap parametersroc.test(roc1, roc2,reuse.auc=FALSE,partial.auc=c(100,90),partial.auc.correct=TRUE,boot.n=1000,boot.stratified=FALSE)# Two ROC curvespower.roc.test(roc1, roc2,reuse.auc=FALSE)power.roc.test(roc1, roc2,power=0.9,reuse.auc=FALSE)# One ROC curvepower.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)?pROC on the R command lineIf you still can’t find an answer, you can:
Download the source code from git, unzip it if necessary, and thentypeR CMD INSTALL pROC. Alternatively, you can use thedevtools package byHadley Wickham to automate the process(make sure you followthe fullinstructions to get started):
if (!requireNamespace("devtools"))install.packages("devtools")devtools::install_github("xrobin/pROC@develop")To run all automated tests and R checks, including slow tests:
cd .. # Run from parent directoryVERSION=$(grep Version pROC/DESCRIPTION | sed "s/.\+ //")R CMD build pROCRUN_SLOW_TESTS=true R CMD check pROC_$VERSION.tar.gzOr from an R command prompt with devtools:
devtools::check()To run automated tests only from an R command prompt:
run_slow_tests <- TRUE # Optional, include slow testsdevtools::test()Thevdiffr package isused for visual tests of plots.
To run all the test cases (incl. slow ones) from the commandline:
run_slow_tests<-TRUEdevtools::test()# Must run the new teststestthat::snapshot_review()To run the checks upon R CMD check, set environment variableNOT_CRAN=1:
NOT_CRAN=1 RUN_SLOW_TESTS=true R CMD check pROC_$VERSION.tar.gzBy default, AppVeyor stores a build cache containing installeddependencies. Sometimes you want to clean the cache, for instance if aGraphics API versionmismatch occurs on R-devel, indicatingthatggplot2 was built with a previous version of R. Forthis you need the AppVeyorAPI key to make aDELETE request:
export APPVEYOR_TOKEN="<your-api-token>"curl-H"Authorization: Bearer $APPVEYOR_TOKEN"-H"Content-Type: application/json"-X DELETE https://ci.appveyor.com/api/projects/xrobin/pROC/buildcacheVersion andDate inDESCRIPTIONNEWSVERSION=$(grep Version pROC/DESCRIPTION | sed "s/.\+ //") && echo $VERSIONR CMD build pROC && R CMD check --as-cran pROC_$VERSION.tar.gzNOT_CRAN=1 RUN_SLOW_TESTS=true R CMD check pROC_$VERSION.tar.gzrhub::check_for_cran()revdepcheck::revdep_check(num_workers=8, timeout = as.difftime(60, units = "mins"))git checkout master && git merge developgit tag v$VERSION && git push --tags