Learn R Programming

alternativeROC (version 1.0.1)

rocperf: ROC curve performances

Description

Range of statistics associated with a ROC curve with confidence interval where applicable. This function is faster than the alternatives provided by the package pROC.

Usage

rocperf(
  x,
  y,
  sensitivities = NULL,
  specificities = NULL,
  conf.level = 0.95,
  fun = NULL,
  seed = 1,
  boot.n = 2000,
  median = FALSE,
  attr = FALSE,
  parallel = FALSE,
  simplify = TRUE,
  ...
)

Value

A data frame with the following columns:

  • n.control: Number of control patients

  • n.case: Number of case patients

  • MannWhitney.pvalue: Mann Whitney U test p-value

  • AUC.pvalue: p-value for the null hypothesis that AUC=0.5

  • AUC: Area under the ROC curve (point estimate)

  • AUC.lCI: Lower limit of 95% confidence interval for AUC

  • AUC.uCI: Upper limit of 95% confidence interval for AUC

  • AUC.lQuart: Lower limit of 50% confidence interval for AUC

  • AUC.uQuart: Upper limit of 50% confidence interval for AUC

  • Se@SpX: Sensitivity at X% specificity

  • Se@SpX.lCI: Lower limit of 95% confidence interval for sensitivity at X% specificity

  • Se@SpX.uCI: Upper limit of 95% confidence interval for sensitivity at X% specificity

  • Se@SpX.lQuart: Lower limit of 95% confidence interval for sensitivity at X% specificity

  • Se@SpX.uQuart: Upper limit of 95% confidence interval for sensitivity at X% specificity

  • Sp@SeX: Specificity at X% sensitivity

  • Sp@SeX.lCI: Lower limit of 95% confidence interval for specificity at X% sensitivity

  • Sp@SeX.uCI: Upper limit of 95% confidence interval for specificity at X% sensitivity

  • Sp@SeX.lQuart: Lower limit of 50% confidence interval for specificity at X% sensitivity

  • Sp@SeX.uQuart: Upper limit of 50% confidence interval for specificity at X% sensitivity

  • Additional columns for statistics computed by the function fun if provided

data.frame with one row with computed statistics in columns.

Arguments

x

Numeric vector containing the predicted value for each observation.

y

Factor, numeric, logical or character vector encoding the response.

sensitivities

Vector of sensitivity thresholds. Default NULL.

specificities

Vector of specificity thresholds. Default NULL.

conf.level

Width of the confidence interval. Default: 0.95 (i.e., 95% CI).

fun

Function to compute additional statistics. Default NULL.

seed

Random seed for bootstrapping. Default 1.

boot.n

Number of bootstrap samples. Default 2e3.

median

If TRUE, return median bootstrap sensitivities and specificities, otherwise return observed values, otherwise the observe value is provided. Default FALSE.

attr

Return bootstrap results and ROC curve as attributes. Default FALSE.

parallel

Parallelise bootstrap. Default FALSE.

simplify

If TRUE, return only median for results of the function fun having one value across bootstraps. Default TRUE.

...

Additional arguments passed to fun if not NULL.

Details

This function computes the area under the ROC curve (AUC) and its confidence interval, the Mann-Whitney U test p-value, and the p-value for the null hypothesis that the AUC is equal to 0.5 (DeLong et al. 1988).

The function also computes the sensitivity at specified specificities and the specificity at specified sensitivities, with confidence intervals and interquartile ranges if bootstrapping is performed.

The function uses the pROC package to compute the ROC curve and confidence intervals, and it can handle parallel processing for bootstrapping.

The function returns a data frame with the computed statistics, including:

  • Number of control and case patients

  • Mann Whitney U test p-value

  • AUC and its confidence intervals

  • Sensitivity at specified specificities and their confidence intervals

  • Specificity at specified sensitivities and their confidence intervals

The function fun must take the following arguments:

  • controls: vector of control values

  • cases: vector of case values

  • thresholds: vector of thresholds used for the ROC curve

  • sensitivities: vector of sensitivities

  • specificities: vector of specificities

  • ...: additional arguments

and return a named vector of values.

Examples

Run this code
if (FALSE) { # interactive()
fu <- function(controls,cases,thr,se,sp,...) {
  r <- pROC::roc(c(rep(0,length(controls)),
                   rep(1,length(cases))),
                 c(controls,cases),
                 quiet=TRUE)
  c(AUC_fun=r$auc) 
}
set.seed(1)
n <- 123
y <- runif(n)<.5
x <- rnorm(n)+y*1
ans <- rocperf(x,y,fun=fu)
ans <- rocperf(x,y,fun=fu,
               senitivities=c(.5,.75,.9),
               specificities=c(.5,.75,.9))
               
}

Run the code above in your browser using DataLab