(Note, this question has been cross-posted on the Cross-Validation site, which I wasn't aware of at the time of initial posting). I'm using the formula found on Wikipedia for calculating Matthew's Correlation Coefficient. It works fairly well, most of the time, but I'm running into problems in my tool's implementation, and I'm not seeing the problem.
$$ MCC = \frac{(TP*TN)-(FP*FN)}{\sqrt{ (TP + FP)( TP + FN )( TN + FP )( TN + FN )} }$$
Which should only return values $\epsilon$ [-1,1]
double ret;
if ((TruePositives + FalsePositives) == 0 || (TruePositives + FalseNegatives) == 0 ||
( TrueNegatives + FalsePositives) == 0 || (TrueNegatives + FalseNegatives) == 0)
//To avoid dividing by zero
ret = (double)(TruePositives * TrueNegatives -
FalsePositives * FalseNegatives);
else{
double num = (double)(TruePositives * TrueNegatives -
FalsePositives * FalseNegatives);
double denom = (TruePositives + FalsePositives) *
(TruePositives + FalseNegatives) *
(TrueNegatives + FalsePositives) *
(TrueNegatives + FalseNegatives);
denom = Math.Sqrt(denom);
ret = num / denom;
}
return ret;
When I use this, as I said it works properly most of the time, but for instance if TP=280, TN = 273, FP = 67, and FN = 20, then we get: $$MCC = \frac{(280*273)-(67*20)}{\sqrt{347*300*340*293}} = \frac{75100}{42196.06}= (approx) 1.78$$ Is this normal behavior of Matthews Correlation Coefficient? I'm a programmer by trade, so statistics aren't a part of my formal training.
Thanks in advance!