disp('LLCorrAnal1fig3.m') ;

sthr1 = 3 ;
sthr2 = 4 ;
sthr3 = 5 ;
dthr1 = -3 ;
dthr2 = -2 ;
dthr3 = -1 ;
dthr4 = 0 ;
dthr5 = log10(5) ;

s1=y(:,1)>sthr1 ;
s2=y(:,1)>sthr2 ;
s3=y(:,1)>sthr3 ;

log_sizes1 = y(s1,1); %size
log_durs1 = y(s1,2); %duration
log_rates1=log_sizes1-log_durs1;
log_sizes2 = y(s2,1); %size
log_durs2 = y(s2,2); %duration
log_rates2=log_sizes2-log_durs2;
log_sizes3 = y(s3,1); %size
log_durs3 = y(s3,2); %duration
log_rates3=log_sizes3-log_durs3;

clear s1 s2 s3;

d1=y(:,2)>dthr1;
d2=y(:,2)>dthr2;
d3=y(:,2)>dthr3;
d4=y(:,2)>dthr4;
d5=y(:,2)>dthr5;

log_sized1 = y(d1,1); %size
log_durd1 = y(d1,2); %duration
log_rated1=log_sized1-log_durd1;
log_sized2 = y(d2,1); %size
log_durd2 = y(d2,2); %duration
log_rated2=log_sized2-log_durd2;
log_sized3 = y(d3,1); %size
log_durd3 = y(d3,2); %duration
log_rated3=log_sized3-log_durd3;
log_sized4 = y(d4,1); %size
log_durd4 = y(d4,2); %duration
log_rated4=log_sized4-log_durd4;
log_sized5 = y(d5,1); %size
log_durd5 = y(d5,2); %duration
log_rated5=log_sized5-log_durd5;

clear d1 d2 d3 d4 d5 ;

sd11=y(:,1)>sthr1 & y(:,2)>dthr1;
log_sizesd11 = y(sd11,1);
log_dursd11 = y(sd11,2); 
log_ratesd11=log_sizesd11-log_dursd11;
clear sd11;

sd21=y(:,1)>sthr2 & y(:,2)>dthr1;
log_sizesd21 = y(sd21,1);
log_dursd21 = y(sd21,2);
log_ratesd21=log_sizesd21-log_dursd21;
clear sd21;

sd31=y(:,1)>sthr3 & y(:,2)>dthr1;
log_sizesd31 = y(sd31,1);
log_dursd31 = y(sd31,2);
log_ratesd31=log_sizesd31-log_dursd31;
clear sd31;

sd12=y(:,1)>sthr1 & y(:,2)>dthr2;
log_sizesd12 = y(sd12,1);
log_dursd12 = y(sd12,2);
log_ratesd12=log_sizesd12-log_dursd12;
clear sd12;

sd22=y(:,1)>sthr2 & y(:,2)>dthr2;
log_sizesd22 = y(sd22,1);
log_dursd22 = y(sd22,2);
log_ratesd22=log_sizesd22-log_dursd22;
clear sd22;

sd32=y(:,1)>sthr3 & y(:,2)>dthr2;
log_sizesd32 = y(sd32,1);
log_dursd32 = y(sd32,2);
log_ratesd32=log_sizesd32-log_dursd32;
clear sd32;

sd13=y(:,1)>sthr1 & y(:,2)>dthr3;
log_sizesd13 = y(sd13,1);
log_dursd13 = y(sd13,2);
log_ratesd13=log_sizesd13-log_dursd13;
clear sd13;

sd23=y(:,1)>sthr2 & y(:,2)>dthr3;
log_sizesd23 = y(sd23,1);
log_dursd23 = y(sd23,2);
log_ratesd23=log_sizesd23-log_dursd23;
clear sd23;

sd33=y(:,1)>sthr3 & y(:,2)>dthr3;
log_sizesd33 = y(sd33,1);
log_dursd33 = y(sd33,2);
log_ratesd33=log_sizesd33-log_dursd33;
clear sd33;

sd14=y(:,1)>sthr1 & y(:,2)>dthr4;
log_sizesd14 = y(sd14,1);
log_dursd14 = y(sd14,2);
log_ratesd14=log_sizesd14-log_dursd14;
clear sd14;

sd24=y(:,1)>sthr2 & y(:,2)>dthr4;
log_sizesd24 = y(sd24,1);
log_dursd24 = y(sd24,2);
log_ratesd24=log_sizesd24-log_dursd24;
clear sd24;

sd34=y(:,1)>sthr3 & y(:,2)>dthr4;
log_sizesd34 = y(sd34,1);
log_dursd34 = y(sd34,2);
log_ratesd34=log_sizesd34-log_dursd34;
clear sd34;

sd15=y(:,1)>sthr1 & y(:,2)>dthr5;
log_sizesd15 = y(sd15,1);
log_dursd15 = y(sd15,2);
log_ratesd15=log_sizesd15-log_dursd15;
clear sd15;

sd25=y(:,1)>sthr2 & y(:,2)>dthr5;
log_sizesd25 = y(sd25,1);
log_dursd25 = y(sd25,2);
log_ratesd25=log_sizesd25-log_dursd25;
clear sd25;

sd35=y(:,1)>sthr3 & y(:,2)>dthr5;
log_sizesd35 = y(sd35,1);
log_dursd35 = y(sd35,2);
log_ratesd35=log_sizesd35-log_dursd35;
clear sd35;

nplot=length(y(:,1));  
left = 0 ;
right = 9 ;
top = 11 ;
bottom = -2 ;

titlefontsize = 15 ;
textfontsize = 6 ;
labelfontsize = 12 ;

plot(y(:,1),y(:,1)-y(:,2), 'c.') ;
axis([left,right,bottom,top]) ;
%title(['log - log Scatterplot, for simulated bivariate normal, n = ' num2str(nplot)],'FontSize',titlefonsize) ;
xlabel('log_{10}(size)','FontSize',labelfontsize) ;
ylabel('log_{10}(rate)','FontSize',labelfontsize) ;
hold on;
plot([sthr1,sthr1],[bottom,top],'r--');
plot([sthr2,sthr2],[bottom,top],'r--'); 
plot([sthr3,sthr3],[bottom,top],'r--'); 
plot([left,right], [left-dthr1,right-dthr1],'r--');
plot([left,right], [left-dthr2,right-dthr2],'r--');
plot([left,right], [left-dthr3,right-dthr3],'r--');
plot([left,right], [left-dthr4,right-dthr4],'r--');
plot([left,right], [left-dthr5,right-dthr5],'r--');

c=corrcoef(y(:,1),y(:,1)-y(:,2));
text(1.5,9.6,[num2str(c(2,1))],'Fontsize',textfontsize, 'color', 'k');
text(1.5,9.2,' (100%)','Fontsize',textfontsize, 'color', 'k');
c=corrcoef(log_sizes1,log_rates1);
text(3,9.6,[num2str(c(2,1))],'Fontsize',textfontsize, 'color', 'k');
text(3,9.2,['(' num2str(round(length(log_sizes1)*1000/nplot)/10) '%)'],'Fontsize',textfontsize, 'color', 'k');
c=corrcoef(log_sizes2,log_rates2);
text(4,9.6,[num2str(c(2,1))],'Fontsize',textfontsize, 'color', 'k');
text(4,9.2,[' (' num2str(round(length(log_sizes2)*1000/nplot)/10) '%)'],'Fontsize',textfontsize, 'color', 'k');
c=corrcoef(log_sizes3,log_rates3);
text(5,9.6,[num2str(c(2,1)) ' (' num2str(round(length(log_sizes3)*1000/nplot)/10) '%)'],'Fontsize',textfontsize, 'color', 'k');

c=corrcoef(log_sized1,log_rated1);
text(1.5,4.5,[num2str(c(2,1)) ' (' num2str(round(length(log_sized1)*1000/nplot)/10) '%)'],'Fontsize',textfontsize, 'color', 'k');
c=corrcoef(log_sized2,log_rated2);
text(1.5,3.5,[num2str(c(2,1)) ' (' num2str(round(length(log_sized2)*1000/nplot)/10) '%)'],'Fontsize',textfontsize, 'color', 'k');
c=corrcoef(log_sized3,log_rated3);
text(1.5,2.5,[num2str(c(2,1)) ' (' num2str(round(length(log_sized3)*1000/nplot)/10) '%)'],'Fontsize',textfontsize, 'color', 'k');
c=corrcoef(log_sized4,log_rated4);
text(1.5,1.6,[num2str(c(2,1)) ' (' num2str(round(length(log_sized4)*1000/nplot)/10) '%)'],'Fontsize',textfontsize, 'color', 'k');
c=corrcoef(log_sized5,log_rated5);
text(1.5,0.2,[num2str(c(2,1)) ' (' num2str(round(length(log_sized5)*1000/nplot)/10) '%)'],'Fontsize',textfontsize, 'color', 'k');
c=corrcoef(log_sizesd11,log_ratesd11);
text(3,6,[num2str(c(2,1))],'Fontsize',textfontsize, 'color', 'k');
text(3,5.6,[' (' num2str(round(length(log_sizesd11)*1000/nplot)/10) '%)'],'Fontsize',textfontsize, 'color', 'k');
c=corrcoef(log_sizesd21,log_ratesd21);
text(4,7,[num2str(c(2,1))],'Fontsize',textfontsize, 'color', 'k');
text(4,6.6,[' (' num2str(round(length(log_sizesd21)*1000/nplot)/10) '%)'],'Fontsize',textfontsize, 'color', 'k');
c=corrcoef(log_sizesd31,log_ratesd31);
text(5,8,[num2str(c(2,1)) ' (' num2str(round(length(log_sizesd31)*1000/nplot)/10) '%)'],'Fontsize',textfontsize, 'color', 'k');
c=corrcoef(log_sizesd12,log_ratesd12);
text(3,5,[num2str(c(2,1))],'Fontsize',textfontsize, 'color', 'k');
text(3,4.6,[' (' num2str(round(length(log_sizesd12)*1000/nplot)/10) '%)'],'Fontsize',textfontsize, 'color', 'k');
c=corrcoef(log_sizesd22,log_ratesd22);
text(4,6,[num2str(c(2,1))],'Fontsize',textfontsize, 'color', 'k');
text(4,5.6,[' (' num2str(round(length(log_sizesd22)*1000/nplot)/10) '%)'],'Fontsize',textfontsize, 'color', 'k');
c=corrcoef(log_sizesd32,log_ratesd32);
text(5,7,[num2str(c(2,1)) ' (' num2str(round(length(log_sizesd32)*1000/nplot)/10) '%)'],'Fontsize',textfontsize, 'color', 'k');
c=corrcoef(log_sizesd13,log_ratesd13);
text(3,4,[num2str(c(2,1))],'Fontsize',textfontsize, 'color', 'k');
text(3,3.6,[' (' num2str(round(length(log_sizesd13)*1000/nplot)/10) '%)'],'Fontsize',textfontsize, 'color', 'k');
c=corrcoef(log_sizesd23,log_ratesd23);
text(4,5,[num2str(c(2,1))],'Fontsize',textfontsize, 'color', 'k');
text(4,4.6,[' (' num2str(round(length(log_sizesd23)*1000/nplot)/10) '%)'],'Fontsize',textfontsize, 'color', 'k');
c=corrcoef(log_sizesd33,log_ratesd33);
text(5,6,[num2str(c(2,1)) ' (' num2str(round(length(log_sizesd33)*1000/nplot)/10) '%)'],'Fontsize',textfontsize, 'color', 'k');
c=corrcoef(log_sizesd14,log_ratesd14);
text(3,3,[num2str(c(2,1))],'Fontsize',textfontsize, 'color', 'k');
text(3,2.6,[' (' num2str(round(length(log_sizesd14)*1000/nplot)/10) '%)'],'Fontsize',textfontsize, 'color', 'k');
c=corrcoef(log_sizesd24,log_ratesd24);
text(4,4,[num2str(c(2,1))],'Fontsize',textfontsize, 'color', 'k');
text(4,3.6,[' (' num2str(round(length(log_sizesd24)*1000/nplot)/10) '%)'],'Fontsize',textfontsize, 'color', 'k');
c=corrcoef(log_sizesd34,log_ratesd34);
text(5,5,[num2str(c(2,1)) ' (' num2str(round(length(log_sizesd34)*1000/nplot)/10) '%)'],'Fontsize',textfontsize, 'color', 'k');
c=corrcoef(log_sizesd15,log_ratesd15);
text(3,2,[num2str(c(2,1))],'Fontsize',textfontsize, 'color', 'k');
text(3,1.6,[' (' num2str(round(length(log_sizesd15)*1000/nplot)/10) '%)'],'Fontsize',textfontsize, 'color', 'k');
c=corrcoef(log_sizesd25,log_ratesd25);
text(4,2,[num2str(c(2,1))],'Fontsize',textfontsize, 'color', 'k');
text(4,1.6,[' (' num2str(round(length(log_sizesd25)*1000/nplot)/10) '%)'],'Fontsize',textfontsize, 'color', 'k');
c=corrcoef(log_sizesd35,log_ratesd35);
text(5,2,[num2str(c(2,1)) ' (' num2str(round(length(log_sizesd35)*1000/nplot)/10) '%)'],'Fontsize',textfontsize, 'color', 'k');
hold off ;
set(gca,'Box','on') ;

pstr = ['LLCorrAnal1fig3'] ;
orient portrait ;
  set(gcf,'PaperSize',[5.0, 5.0]) ; 
  set(gcf,'PaperPosition',[0.25, 0.25, 4.5, 4.5]) ;
print('-dpsc2',[pstr '.ps']) ;