?? roc.m
字號:
function roc(x,y)
% ROC - Receiver Operating Characteristics.
% The ROC graphs are a useful tecnique for organizing classifiers and
% visualizing their performance. ROC graphs are commonly used in medical
% decision making.
% If you have downloaded partest (ID: 12705) the routine will compute
% several data on test performance.
%
% Syntax: roc(x,y)
%
% Input: x and y - two arrays with the value of the test in unhealthy (x)
% and healthy (y) subjects
%
% Output: The ROC plot;
% The Area under the curve with Standard error and Confidence
% interval and comment.
% Cut-off point for best sensibility and specificity.
% (Optional) the test performance at cut-off point.
%
% Example:
% load rocdata
% roc(x,y)
%
% Created by Giuseppe Cardillo
% CEINGE - Advanced Biotechnologies
% Via Comunale Margherita, 482
% 80145
% Napoli - Italy
% cardillo@ceinge.unina.it
lx=length(x); ly=length(y); %number of subjects
%join both arrays and add a label (1-unhealthy; 2-healthy)
z=sortrows([x(:) repmat(1,lx,1); y(:) repmat(2,ly,1)],1);
%find unique values in z
labels=unique(z(:,1));
ll=length(labels); %count unique value
a=zeros(ll,2); %array preallocation
for K=1:ll
i=length(z(z(:,1)<=labels(K))); %set unique value(i) as cut-off
table(1)=length(z(z(1:i,2)==1)); %true positives
table(2)=length(z(z(1:i,2)==2)); %false positives
test=[table;[lx ly]-table]; %complete the table
a(K,:)=(diag(test)./sum(test)')'; %Sensibility and Specificity
end
xroc=1-a(:,2); yroc=a(:,1); %ROC points
%the best cut-off point is the closest point to (1,1)
d=sqrt(xroc.^2+(1-yroc).^2); %apply the Pitagora's theorem
[y,j]=min(d); %find the least distance
co=labels(j); %set the cut-off point
AUCt=1-trapz(yroc,xroc); %estimate the area under the curve
%standard error of area
SE=sqrt((-AUCt*(AUCt-1)*(AUCt^2*(1+lx+ly)+AUCt*(1-2*ly)-(3+lx))/((AUCt-2)*(1+AUCt)*lx*ly)));
%confidence interval
ci=AUCt+[-1 1].*(1.96*SE);
%Performance of the classifier
if AUCt==1
str='Perfect test';
elseif AUCt>=0.90 && AUCt<=0.99
str='Excellent test';
elseif AUCt>=0.80 && AUCt<=0.89
str='Good test';
elseif AUCt>=0.70 && AUCt<=0.79
str='Fair test';
elseif AUCt>=0.60 && AUCt<=0.69
str='Poor test';
elseif AUCt>=0.50 && AUCt<=0.59
str='Fail test';
end
%display results
disp('ROC CURVE ANALYSIS')
disp(' ')
tr=repmat('-',1,80);
disp(tr)
disp(' AUC S.E. 95% C.I. Comment')
disp(tr)
fprintf('%10.5f %10.5f %10.5f %10.5f ',AUCt,SE,ci)
disp(str)
disp(tr)
disp(' ')
fprintf('cut-off point for best sensibility and specificity (blu circle in plot)= %0.4f\n',co)
%display graph
plot(xroc,yroc,'r.-',xroc(j),yroc(j),'bo',[0 1],[0 1],'k')
xlabel('False positive rate (1-specificity)')
ylabel('True positive rate (sensibility)')
title('ROC curve')
axis square
disp('Press a key to continue'); pause
%if partest.m was downloaded
try
%table at cut-off point
i=length(z(z(:,1)<=co));
table(1)=length(z(z(1:i,2)==1));
table(2)=length(z(z(1:i,2)==2));
test=[table;[lx ly]-table];
disp('Table at cut-off point')
disp(test)
disp(' ')
partest(test)
catch
disp('if you want to calculate the test performance at cutoff point please download partest from Fex')
end
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -