Pull a Classification Performance Metric/Statistic
pull_stat.RdIndexes into the S3 summary method for confusion_matrix
class object.
Usage
pull_stat(
x,
which = c("Sensitivity", "Recall", "Specificity", "Precision", "PPV", "NPV",
"Accuracy", "MCC", "AUC", "Brier", "Error", "F_measure", "G_mean", "Wt_Acc")
)Details
Optional statistics are restricted to the output of the summary
method. One of:
"Sensitivity"
"Recall"
"Specificity"
"Precision"
"PPV"
"NPV"
"Accuracy"
"Error"
"F_measure"
"G_mean"
"Wt_Acc"
Examples
n <- 20
withr::with_seed(22, {
true <- sample(c("control", "disease"), n, replace = TRUE)
pred <- runif(n)
})
# Summary of confusion matrix
c_mat <- calc_confusion(true, pred, pos_class = "disease") |> summary()
class(c_mat)
#> [1] "summary_confusion_matrix" "list"
# pull out elements
pull_stat(c_mat, "Spec")
#> [1] 0.5714286
pull_stat(c_mat, "Sens")
#> [1] 0.4615385
pull_stat(c_mat, "Recall") # same
#> [1] 0.4615385
pull_stat(c_mat, "Accuracy")
#> [1] 0.5
pull_stat(c_mat, "Error") # 1 - accuracy
#> [1] 0.5
pull_stat(c_mat, "PPV")
#> [1] 0.6666667
pull_stat(c_mat, "NPV")
#> [1] 0.3636364
pull_stat(c_mat, "F_measure")
#> [1] 0.5454545
pull_stat(c_mat, "Wt_Acc")
#> [1] 0.489011