function uroccomp(varargin)
% UROCCOMP - Compare two unpaired ROC curves
% The ROC graphs are a useful tecnique for organizing classifiers and
% visualizing their performance. ROC graphs are commonly used in medical
% decision making.
% This function compares two unpaired ROC curves using my previously
% submitted routine ROC
% http://www.mathworks.com/matlabcentral/fileexchange/19950
%
% Syntax: uroccomp(x,y,alpha)
%
% Input: x and y - These are the data matrix.
% The first column is the column of the data value;
% The second column is the column of the tag:
% unhealthy (1) and healthy (0).
% alpha - significance level (default 0.05)
%
% Output: The ROC plots;
% The z-test to compare Areas under the curves
%
% Example:
% load uroccompdata
% uroccomp(x,y)
%
% Created by Giuseppe Cardillo
% giuseppe.cardillo-edta@poste.it
%
% To cite this file, this would be an appropriate format:
% Cardillo G. (2009) uROCcomp: compare two unpaired ROC curves.
% http://www.mathworks.com/matlabcentral/fileexchange/23020
%Input Error handling
args=cell(varargin);
nu=numel(args);
if isempty(nu) || nu==1
error('Warning: almost two data matrix are required')
elseif nu>3
error('Warning: Max three input data are required')
end
default.values = {[],[],0.05};
default.values(1:nu) = args;
[x y alpha] = deal(default.values{:});
if isvector(x) || isvector(y)
error('Warning: X and Y must be matrix')
end
if ~all(isfinite(x(:))) || ~all(isnumeric(x(:))) || ~all(isfinite(y(:))) || ~all(isnumeric(y(:)))
error('Warning: all X and Y values must be numeric and finite')
end
x(:,2)=logical(x(:,2));
if all(x(:,2)==0)
error('Warning: there are only healthy subjects in X!')
end
if all(x(:,2)==1)
error('Warning: there are only unhealthy subjects in X!')
end
y(:,2)=logical(y(:,2));
if all(y(:,2)==0)
error('Warning: there are only healthy subjects in Y!')
end
if all(y(:,2)==1)
error('Warning: there are only unhealthy subjects in Y!')
end
if nu==3
if ~isscalar(alpha) || ~isnumeric(alpha) || ~isfinite(alpha) || isempty(alpha)
error('Warning: it is required a numeric, finite and scalar ALPHA value.');
end
if alpha <= 0 || alpha >= 1 %check if alpha is between 0 and 1
error('Warning: ALPHA must be comprised between 0 and 1.')
end
end
clear args default nu
curve1=roc(x,alpha,0);
curve2=roc(y,alpha,0);
%Areas
A=[curve1.AUC,curve2.AUC];
%standard errors
SE=[curve1.SE,curve2.SE];
%display results
disp('ROC CURVES COMPARE')
disp(' ')
tr=repmat('-',1,80);
disp(tr)
disp(' ROC1 ROC2')
disp(tr)
fprintf('AUC %0.4f %18.4f\n',A(1),A(2))
fprintf('S.E. %0.4f %18.4f\n',SE(1),SE(2))
disp(tr)
z=abs(diff(A))/realsqrt(sum(SE.^2));
p=(1-0.5*erfc(-z/realsqrt(2)))*2; %p-value
fprintf('z\t\t2-tails p-value\n')
fprintf('%0.4f\t\t\t\t\t%0.6f',z,p)
if p<=alpha
fprintf('\t\tThe areas are statistically different\n')
else
fprintf('\t\tThe areas are not statistically different\n')
end
disp(tr)
%display graph
hold on
H1=plot([0;curve1.xr],[0;curve1.yr],'r.-');
H2=plot([0;curve2.xr],[0;curve2.yr],'b.-');
plot([0 1],[0 1],'k')
hold off
xlabel('False positive rate (1-Specificity)')
ylabel('True positive rate (Sensitivity)')
title('ROC curves')
legend([H1 H2],'Curve 1','Curve 2','location','NorthEastOutside')
axis square