multiClassCM: Confusion matrix summaries

View source: R/multiClassCM.R

multiClassCMR Documentation

Confusion matrix summaries

Description

Calculates summaries from cross-tabulated reference and prediction labels for a multi-class variable.

Usage

multiClassCM(
  x,
  y,
  seed = 20,
  num.boot = 1000,
  conf.level = 0.95,
  digits = 2,
  method = "wilson"
)

Arguments

x

a vector of reference classes

y

a vector of predicted classes

seed

random seed for bootstrapping

num.boot

number of times to bootstrap. Defaults to 1000.

conf.level

confidence level. Defaults to 95%.

digits

number of digits to round summaries to

method

method for obtaining confidence intervals for binomial probabilities. See Hmisc::binconf for details.

Details

Given two multi-class variables summarized in a confusion matrix, this function provides performance summaries. It provides overall accuracy with confidence intervals, as well as per class accuracy, sensitivity, specificity, positive predictive value (PPV), negative predictive value (NPV). if variable entered is binary, it will automatically call binaryCM

Value

A confusion matrix for the predicted and reference classes. Then the estimated statistics along with bootstrapped confidence intervals. A list with the following elements

Accuracy

Accuracy point estimate, lower bound and upper bound for bootstrapped CI

Sensitivity

Sensitivity point estimate, lower bound and upper bound for bootstrapped CI

Specificity

Specificity point estimate, lower bound and upper bound for bootstrapped CI

PPV

PPV point estimate, lower bound and upper bound for bootstrapped CI

NPV

NPV point estimate, lower bound and upper bound for bootstrapped CI

kappa

kappa point estimate, lower bound and upper bound for bootstrapped CI

Author(s)

Aline Talhouk, Derek Chiu

See Also

Other confusion matrix functions: binaryCM(), binaryCMAsHTML()

Examples

### 95% CI from 1000 bootstraped samples
set.seed(23)
k <- 3
(x <- factor(sample(1:k, 100, replace = TRUE, prob = c(0.15, 0.25, 0.6))))
(y <- factor(sample(1:k, 100, replace = TRUE, prob = c(0.05, 0.4, 0.65))))
prop.table(table(y))
multiClassCM(x, y)

### 90% CI from 500 bootstrapped samples
multiClassCM(x, y, num.boot = 500, conf.level = 0.90)

### Round to 2 digits
multiClassCM(x, y, digits = 2)

TalhoukLab/biostatUtil documentation built on April 14, 2025, 4:15 a.m.