close all
clear all
lw = 2;  
set(0, 'DefaultAxesFontSize', 16);
fs = 14;
msize = 5;
   %ROC ADA Example    
   %load ADA.mat
   load 'C:\BESTAT\ROC\ROCdat\ADA.mat'
        % columns in ADA.mat are
        % 1. ADA level (ordered decereasingly)
        % 2. indicator of case TB
        % 3. indicator of noncase CA
    cumultruepos  = cumsum(ada(:,2));
    cumulfalsepos = cumsum(ada(:,3));
    alldisease = cumultruepos(end);
    allcontrol = cumulfalsepos(end);
        % these are true positives/false positives if the
        % threshold level is from the sequence ada(:,1).
     seth = cumultruepos/alldisease;    %sensitivity at the threshold
     cspth = cumulfalsepos/allcontrol;  %1-specificity at the threshold
     
     figure(1)
     plot(cspth,seth,'linewidth',lw) %ROC is a plot of sensitivity against (1-specificity)
     hold on
     fill([cspth' 1 1 0],[seth' 1 0 0],'y')
     plot([0 1],[0 1],'g--','LineWidth', lw)
     
     %epsi=0;plot([0 0.3-epsi ],[0.7+epsi 1],'g--','LineWidth', lw)
     
     xlabel('1 - specificity')
     ylabel('sensitivity')
     text('Interpreter','latex',...
	'String','$\fbox{Area = 0.8646}$',...
	'Position',[0.55 .45],...
	'FontSize',17) 

     print -depsc 'C:\BESTAT\ROC\ROCeps\adaroc.eps'
     area = auc(cspth, seth)  %0.8646
     figure(2)
     plot(ada(:,1),(seth-cspth)/sqrt(2),'linewidth',lw)
     hold on
     plot(37,0,'o','LineWidth',2,...
                       'MarkerEdgeColor','k',...
                       'MarkerFaceColor','g',...
                       'MarkerSize',10)
     text(37,0.02,'37')
     xlabel('ADA level')
     ylabel('Youden index')
     print -depsc 'C:\BESTAT\ROC\ROCeps\adaroc2.eps'
     
     %youden index
     yi = max((seth-cspth)/sqrt(2))       %0.4910
     %ADA level corresponding to YI
     ada((seth-cspth)/sqrt(2)== yi , 1)   %37
     % sensitivity/specificity at YI
     seth((seth-cspth)/sqrt(2)== yi)      %0.8904
     1 - cspth((seth-cspth)/sqrt(2)== yi) %0.8039
     
     