AUC: AUC

Description Usage Arguments Details Value See Also Examples

View source: R/AUC.R

Description

Compute the Area Under the ROC Curve (AUC) of a predictor and possibly its 95% confidence interval.

Usage

1
2
3
AUC(pred, target, digits = NULL)

AUCBoot(pred, target, nboot = 10000, seed = NA, digits = NULL)

Arguments

pred

Vector of predictions.

target

Vector of true labels (must have exactly two levels, no missing values).

digits

See round. Default doesn't use rounding.

nboot

Number of bootstrap samples used to evaluate the 95% CI. Default is 1e4.

seed

See set.seed. Use it for reproducibility. Default doesn't set any seed.

Details

Other packages provide ways to compute the AUC (see this answer). I chose to compute the AUC through its statistical definition as a probability:

P(score(x_{case}) > score(x_{control})).

Note that I consider equality between scores as a 50%-probability of one being greater than the other.

Value

The AUC, a probability, and possibly its 2.5% and 97.5% quantiles (95% CI).

See Also

wilcox.test

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
set.seed(1)

AUC(c(0, 0), 0:1) # Equality of scores
AUC(c(0.2, 0.1, 1), c(0, 0, 1)) # Perfect AUC
x <- rnorm(100)
z <- rnorm(length(x), x, abs(x))
y <- as.numeric(z > 0)
print(AUC(x, y))
print(AUCBoot(x, y))

# Partial AUC
pAUC <- function(pred, target, p = 0.1) {
  val.min <- min(target)
  q <- quantile(pred[target == val.min], probs = 1 - p)
  ind <- (target != val.min) | (pred > q)
  bigstatsr::AUC(pred[ind], target[ind]) * p
}
pAUC(x, y)
pAUC(x, y, 0.2)

Example output

sh: 1: cannot create /dev/null: Permission denied
sh: 1: wc: Permission denied
[1] 0.5
[1] 1
[1] 0.8071659
      Mean       2.5%      97.5%         Sd 
0.80608943 0.70540804 0.88921345 0.04767838 
[1] 0.00962963
[1] 0.05802469

bigstatsr documentation built on March 14, 2020, 1:09 a.m.