Classification accuracy and agreement estimates
class_acc.RdClassification accuracy and agreement estimates for 2x2 contingency tables.
Details
The table must be in the following format for correct results:
| actual + | actual - | |
| estimate + | a | b |
| estimate - | c | d |
Wilson confidence intervals are returned for the proportion estimates.
Functions from the DescTools package are used for confidence intervals.
Estimates returned include:
Estimated prevalence: The estimated proportion of subjects with positive outcome (based on the estimated label).
Actual prevalence: The actual proportion of subjects with positive outcome (based on the actual label).
Estimated accuracy: Among all subjects, the proportion who had a correct classification.
Sensitivity: Among subjects with actual positive outcome, the proportion that were correctly classified with positive outcome.
Specificity: Among subjects with actual negative outcome, the proportion that were correctly classified with negative outcome.
Positive predictive value: Among subjects with estimated positive outcome, the proportion that were correctly classified with positive outcome. (Accuracy of a positive test)
Negative predictive value: Among subjects with estimated negative outcome, the proportion that were correctly classified with negative outcome. (Accuracy of a negative test)
Proportion of false positives: Among subjects with actual negative outcome, the proportion that were incorrectly classified as positive outcome.
Proportion of false negative: Among subjects with actual positive outcome, the proportion that were incorrectly classified as negative outcome.
Cohen's Kappa: A measure of agreement between the two tests that adjusts for the amount of agreement that would be expected due to chance alone.
Examples
#----------------------------------------------------------------------------
# class_acc() examples
#----------------------------------------------------------------------------
library(bkstat)
# simulate random data
new_test <- sample(
x = c("positive", "negative"),
size = 200,
replace = TRUE,
prob = c(0.25, 0.75)
)
standard_test <- sample(
x = c("positive", "negative"),
size = 200,
replace = TRUE,
prob = c(0.25, 0.75)
)
# ensure correct matrix structure order
new_test <- factor(new_test, levels = c("positive", "negative"))
standard_test <- factor(standard_test, levels = c("positive", "negative"))
tab <- table(new_test = new_test, standard_test = standard_test)
# results
class_acc(x = tab)
#> summary estimate lower_ci upper_ci
#> 1 Apparent prevalance 0.27500000 0.21779700 0.3406834
#> 2 True prevalance 0.27000000 0.21323450 0.3354344
#> 3 Diagnostic accuracy 0.63500000 0.56631703 0.6985947
#> 4 Sensitivity 0.33333333 0.22241417 0.4663904
#> 5 Specificity 0.74657534 0.67032209 0.8101858
#> 6 Positive predictive value 0.32727273 0.21813066 0.4589678
#> 7 Negative predictive value 0.75172414 0.67552026 0.8149345
#> 8 Proportion of false positives 0.25342466 0.18981423 0.3296779
#> 9 Proportion of false negatives 0.66666667 0.53360964 0.7775858
#> 10 Cohen's kappa 0.07944515 -0.06370327 0.2225936