Performance measures for two-class classification

calculate_performance(truth, prediction, pos_label = levels(truth)[2])

Arguments

truth

(factor)
A factor vector with "true"/reference classes.

prediction

A vector with predicted classes.

pos_label

(character(1))
A string with the name of positive group. By default, the second level of factor truth is treated as positive.

Value

A matrix with the following columns:

  • tp (number of true positives), fn (number of false negatives), fp (number of false positives), tn (number of true negatives), sens (sensitivity), spec (specificity), ppv (positive predictive value), npv (negative predictive value), youden (Youden's j index), kappa (Cohen's kappa).

  • attribute labels contains a named vector with elements pos_label and neg_label, which indicate labels of positive and negative groups respectively.



See also

Author

Vilmantas Gegzna

Examples

(truth <- gl(n = 2, k = 3, length = 20, labels = c("H", "S")))
#> [1] H H H S S S H H H S S S H H H S S S H H #> Levels: H S
(prediction <- rev(truth))
#> [1] H H S S S H H H S S S H H H S S S H H H #> Levels: H S
calculate_performance(truth, prediction)
#> tp fn fp tn sens spec ppv npv bac youden kappa #> 1 6 3 3 8 0.67 0.73 0.67 0.73 0.70 0.39 0.39
calculate_performance(truth, prediction, pos_label = "S")
#> tp fn fp tn sens spec ppv npv bac youden kappa #> 1 6 3 3 8 0.67 0.73 0.67 0.73 0.70 0.39 0.39
calculate_performance(truth, prediction, pos_label = "H")
#> tp fn fp tn sens spec ppv npv bac youden kappa #> 1 8 3 3 6 0.73 0.67 0.73 0.67 0.70 0.39 0.39