-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmatthewscorr.m
29 lines (27 loc) · 1005 Bytes
/
matthewscorr.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
% R = matthewscorr(X, Y)
%
% computes the 'Matthews correlation coefficient' as described on Wikipedia
% (http://en.wikipedia.org/wiki/Matthews_correlation_coefficient)
%
% It's supposedly a special correlation coefficient for binary data (e.g.
% in binary classification) and computes the correlation based on true and
% false postivies and negatives, but the correlation coefficients seem to
% be the same as those computed by Matlab's corrcoef.
%
% in:
% X - binary data set 1
% [N, nsets] = size
% Y - binary data set 2
% [N, nsets] = size
% out:
% R - Matthews correlation coefficient between columns of X and Y
% [1, nsets] = size
% author:
% Sebastian Bitzer ([email protected])
function R = matthewscorr(X, Y)
TP = sum(X == 1 & Y == 1);
FP = sum(X == 0 & Y == 1);
TN = sum(X == 0 & Y == 0);
FN = size(X, 1) - TP - FP - TN;
R = (TP .* TN - FP .* FN) ./ ...
sqrt( (TP + FP) .* (TP + FN) .* (TN + FP) .* (TN + FN) );