function [AUC] = computeROC(data1,data2,style);

list = [-inf,unique([data1,data2]),inf];

hits = nan(1,length(list));
miss = nan(1,length(list));
fa   = nan(1,length(list));
corR =  nan(1,length(list));

lCount = 0;
  
for ll = list
        
  lCount = lCount+1;
  hits(lCount) = sum(data2>=ll);
  fa(lCount)   = sum(data1>=ll);
  corR(lCount) = sum(data1<ll);
  miss(lCount) = sum(data2<ll);
  
  
end

fpRate = (fa./(fa+corR));
tpRate = (hits./(hits+miss));

if nargin>2
  plot(fpRate,tpRate,style);
end

AUC = compAUC(fpRate,tpRate,fa(1)+corR(1),hits(1)+miss(1));







function [AUC,SE] = compAUC(fpRate,tpRate,n1,n2);

A = -diff(fpRate);
B = tpRate(1:end-1);
C = tpRate(2:end);




AUC = sum(A.*(B+C)/2);

if nargin>2

  Q1 = AUC/(2-AUC);
  Q2 = 2*AUC*AUC/(1+AUC);

  SE = ...
          sqrt((AUC*(1-AUC)+(n1-1)*(Q1-AUC*AUC)+(n2-1)*(Q2-AUC*AUC))/(n1*n2));


else
  SE=nan;
end
