-
Notifications
You must be signed in to change notification settings - Fork 5
/
get_aroc.m
45 lines (39 loc) · 898 Bytes
/
get_aroc.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
function [aroc,pval] = get_aroc(lab,dat)
% GET_AROC Get area under ROC curve
%
% Usage:
% >> [aroc] = get_aroc(lab,dat)
%
% Input arguments:
% - lab = category labels
% - dat = data
%
% Valentin Wyart <valentin.wyart@ens.fr>
if nargin < 2
error('missing input argument(s)!');
end
% % preprocess category labels
% lab = lab(:); % columnize category labels
% [lab_lst,~,lab] = unique(lab); % re-label using integers
%
% % preprocess data
% dat = dat(:); % columnize data
% if length(lab_lst) ~= 2 || length(dat) ~= length(lab)
% error('invalid data format!');
% end
x = dat(lab == 1);
y = dat(lab == 2);
m = length(x);
n = length(y);
% compute area under ROC curve
aroc = 0;
for i = 1:m
% changed > to < here. MC
aroc = aroc+nnz(y < x(i))+0.5*nnz(y == x(i));
end
aroc = aroc/m/n;
if nargout > 1
% compute corresponding p-value
pval = ranksum(x,y);
end
end