Skip to contents

Computes the concordance statistic (C-statistic), equivalent to the area under the ROC curve (AUC), for predicted values and a binary outcome.

Usage

cStat(x, ...)

# Default S3 method
cStat(x, ref, conf.level = NA, sides = c("two.sided", "left", "right"), ...)

Arguments

x

a numeric vector of predicted values. Methods for fitted models are provided by the package alloy.

...

additional arguments passed to methods

ref

binary response vector (numeric, logical, or factor)

conf.level

confidence level for the interval; NA (default) suppresses interval calculation

sides

character string specifying the sidedness of the confidence interval (one of "two.sided" (default), "left" or "right"). The open side is reported at the range boundary, 0 or 1. See ConfidenceIntervals().

Value

if conf.level = NA, an unnamed numeric scalar between 0 and 1; otherwise a named numeric vector with elements:

est

point estimate of the C-statistic.

lci

lower confidence interval bound.

uci

upper confidence interval bound.

Details

The C-statistic is defined as the probability that, for a randomly chosen pair of observations with different outcomes, the observation with the higher predicted value has the higher observed outcome.

Ties in predicted values are handled by assigning a weight of 0.5.

ref is converted with as.numeric(factor(resp)) - 1, so the second level in sort order counts as the event - 1 for a 0/1 coding, TRUE for a logical, and the second factor level otherwise. Getting this backwards returns \(1 - C\) rather than an error, so check the level order when the response is a factor with unusual labels.

This implementation uses:

  • O(n log n) concordance computation

  • Parallel bootstrap confidence intervals via RcppParallel

  • Efficient memory handling

The number of bootstrap samples can be supplied through ... as R; the default is 1000.

Random number generation

A confidence level triggers a bootstrap, which draws a seed from R's global random number generator and therefore advances it. Call base::set.seed() beforehand for reproducible intervals.

See also

Other assoc.ordinal: conDisPairs(), kendallW(), ordAssocs()

Examples

# Default method
set.seed(1)
x <- runif(100)
y <- rbinom(100, 1, 0.5)
cStat(x, ref = y)
#> [1] 0.4569243