Skip to contents

$$MCC = \frac{TP \cdot TN - FP \cdot FN}{\sqrt{(TP+FP)(TP+FN)(TN+FP)(TN+FN)}}$$

Usage

morie_mcc_counts(tp, tn, fp, fn)

Arguments

tp, tn, fp, fn

Non-negative integer counts of true positives, true negatives, false positives and false negatives.

Value

Named list with value, statistic (the same number), accuracy, tp, tn, fp, fn, n, method.

Details

The coefficient stays informative under class imbalance, where accuracy does not: it uses all four cells of the confusion matrix rather than only the diagonal. It ranges over [-1, 1], with 0 meaning no better than chance and negative values meaning the predictions run opposite to the truth.

If any of the four marginal sums is zero the denominator vanishes. The coefficient is then undefined, and the convention followed here is to report 0 and warn, rather than return NaN.

Mirrors morie.fn.mcc on the Python side. See morie_matthews_corrcoef for the label-vector form.

References

Matthews BW (1975). Comparison of the predicted and observed secondary structure of T4 phage lysozyme. Biochimica et Biophysica Acta, 405(2), 442-451.

Examples

morie_mcc_counts(tp = 20, tn = 30, fp = 5, fn = 5)$value
#> [1] 0.6571429