1

(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!

Isaac
  • 113

1 Answers1

0

The Matthews Correlation Coefficient ranges between $-1$ and $1$. In the final fraction that is given in the question, there is some error in the calculation of the denominator, since its numerical value is $101835$, not $42196$. This leads to a MCC of $\approx 0.73$.

Anatoly
  • 17,079