Learn R Programming

pROC (version 1.3.1)

pROC-package: pROC

Description

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.

Arguments

encoding

UTF-8

Abbreviations

The following abbreviations are employed extensively in this package:
  • ROC: receiver operating characteristic
  • AUC: area under the ROC curve
  • pAUC: partial area under the ROC curve
  • CI: confidence interval
  • SP: specificity
  • SE: sensitivity

Functions

ll{ roc Build a ROC curve auc Compute the area under the ROC curve ci Compute confidence intervals of a ROC curve ci.auc Compute the CI of the AUC ci.se Compute the CI of sensitivities at given specificities ci.sp Compute the CI of specificities at given sensitivities ci.thresholds Compute the CI of specificity and sensitivity of thresholds coords Coordinates of a ROC curve lines.roc Add a ROC line to a ROC plot plot.ci Plot CIs plot.roc Plot a ROC curve print Print a ROC curve object roc.test Compare the AUC of two correlated ROC curves smooth Smooth a ROC curve }

Dataset

This package comes with a dataset of 141 patients with aneurysmal subarachnoid hemorrhage: aSAH.

Installing and using

To install this package, make sure you are connected to the internet and issue the following command in the R prompt: packages.install("pROC") To load the package in R: library(pROC)

Progress bars

A progressbar shows the progress of bootstrap operations. It is handled by the plyr package, and is created by the progress_* family of functions. Sensible defaults are guessed during the package loading:

The default can be changed with the option pROCProgress. The option must be a list with a name item setting the type of progress bar (none, win, tk or text). Optional items of the list are width, char and style, corresponding to the arguments to the underlying progressbar functions. For example, to force a text progress bar: options(pROCProgress = list(name = "text", width = NA, char = "=", style = 3)

To inhibit the progress bars completely: options(pROCProgress = list(name = "none"))

Details

The basic unit of the pROC package is the roc function. It will build a ROC curve, smooth it if requested (if smooth=TRUE), compute the AUC (if auc=TRUE), the confidence interval (CI) if requested (if ci=TRUE) and plot the curve if requested (if plot=TRUE).

The roc function will call smooth.roc, auc, ci and plot as necessary. See these individual functions for the arguments that can be passed to them through roc. These function can be called separately.

Two paired ROC curves (that is roc objects with the same response) can be compared with the roc.test function.

References

Tom Fawcett (2006) ``An introduction to ROC analysis''. Pattern Recognition Letters 27, 861--874. DOI: 10.1016/j.patrec.2005.10.010.

See Also

CRAN packages ROCR, verification or Bioconductor's roc for ROC curves.

CRAN packages plyr and MASS employed in this package.

Examples

Run this code
data(aSAH)

# Build a ROC object and compute the AUC
roc(aSAH$outcome, aSAH$s100b)
roc(outcome ~ s100b, aSAH)

# Smooth ROC curve
roc(outcome ~ s100b, aSAH, smooth=TRUE)

# more options, CI and plotting
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)

## Confidence intervals ##

# CI of the AUC
ci(roc2)

# CI of the curve
sens.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 shape
plot(roc2, add=TRUE)

# CI of thresholds
plot(ci.thresholds(roc2))


## Comparisons ##

# 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)

Run the code above in your browser using DataLab