load('Fig2andSupFig_RippleRateComparison')

sublist=[2:7];
ecd_nr_cond=[];ecd_rr_cond=[];ecd_nr_val=[];
rtv_nr_cond = [];  rtv_rr_cond=[];
ecd_nr_cond_hA=[];ecd_nr_cond_lA=[];
ecd_nr_sim=[]; ecd_nr_sim_lA=[]; ecd_nr_sim_hA=[]; 
ecd_rr_sim=[]; ecd_rr_sim_lA=[]; ecd_rr_sim_hA=[]; 
rtv_nr_sim=[];
for nsub = sublist
    ecd_nr_cond(nsub,:) = [mean(ecd_nr(sub'==nsub & trial_cond_outcome==1)) mean(ecd_nr(sub'==nsub & trial_cond_outcome==2)) ... 
        mean(ecd_nr(sub'==nsub & trial_cond_aro==1)) mean(ecd_nr(sub'==nsub & trial_cond_aro==2))];  
 rtv_nr_cond(nsub,:) = [mean(rtv_nr_present(sub'==nsub & trial_cond_outcome==1)) mean(rtv_nr_present(sub'==nsub & trial_cond_outcome==2)) ... 
        mean(rtv_nr_present(sub'==nsub & trial_cond_aro==1)) mean(rtv_nr_present(sub'==nsub & trial_cond_aro==2))];      
     ecd_nr_sim(nsub,:) = [mean(ecd_nr(sub'==nsub & trial_cond_sim==1)) mean(ecd_nr(sub'==nsub & trial_cond_sim==2))]; 
     ecd_nr_sim_lA(nsub,:) = [mean(ecd_nr(sub'==nsub & trial_cond_sim==1 & trial_cond_aro==1)) mean(ecd_nr(sub'==nsub & trial_cond_sim==2 & trial_cond_aro==1))]; 
     ecd_nr_sim_hA(nsub,:) = [mean(ecd_nr(sub'==nsub & trial_cond_sim==1 & trial_cond_aro==2)) mean(ecd_nr(sub'==nsub & trial_cond_sim==2 & trial_cond_aro==2))]; 
     rtv_nr_sim(nsub,:) = [mean(rtv_nr_present(sub'==nsub & trial_cond_sim==1)) mean(rtv_nr_present(sub'==nsub & trial_cond_sim==2))]; 

     ecd_rr_sim(nsub,:) = [mean(ecd_rr(sub'==nsub & trial_cond_sim==1)) mean(ecd_rr(sub'==nsub & trial_cond_sim==2))]; 
     ecd_rr_sim_lA(nsub,:) = [mean(ecd_rr(sub'==nsub & trial_cond_sim==1 & trial_cond_aro==1)) mean(ecd_rr(sub'==nsub & trial_cond_sim==2 & trial_cond_aro==1))]; 
     ecd_rr_sim_hA(nsub,:) = [mean(ecd_rr(sub'==nsub & trial_cond_sim==1 & trial_cond_aro==2)) mean(ecd_rr(sub'==nsub & trial_cond_sim==2 & trial_cond_aro==2))]; 

     
    ecd_rr_cond(nsub,:) = [mean(ecd_rr(sub'==nsub & trial_cond_outcome==1)) mean(ecd_rr(sub'==nsub & trial_cond_outcome==2)) ... 
        mean(ecd_rr(sub'==nsub & trial_cond_aro==1)) mean(ecd_rr(sub'==nsub & trial_cond_aro==2))];  
    

    ecd_nr_cond_hA(nsub,:)=[mean(ecd_nr(sub'==nsub & trial_cond_aro==2 & trial_cond_outcome==1)) mean(ecd_nr(sub'==nsub & trial_cond_aro==2 & trial_cond_outcome==2))];
    ecd_nr_cond_lA(nsub,:)=[mean(ecd_nr(sub'==nsub & trial_cond_aro==1 & trial_cond_outcome==1)) mean(ecd_nr(sub'==nsub & trial_cond_aro==1 & trial_cond_outcome==2))];
    ecd_rr_cond_hA(nsub,:)=[mean(ecd_rr(sub'==nsub & trial_cond_aro==2 & trial_cond_outcome==1)) mean(ecd_rr(sub'==nsub & trial_cond_aro==2 & trial_cond_outcome==2))];
    ecd_rr_cond_lA(nsub,:)=[mean(ecd_rr(sub'==nsub & trial_cond_aro==1 & trial_cond_outcome==1)) mean(ecd_rr(sub'==nsub & trial_cond_aro==1 & trial_cond_outcome==2))];


    ecd_nr_present_cond(nsub,:) = [mean(ecd_nr_present(sub'==nsub & trial_cond_outcome==1)) mean(ecd_nr_present(sub'==nsub & trial_cond_outcome==2)) ... 
        mean(ecd_nr_present(sub'==nsub & trial_cond_aro==1)) mean(ecd_nr_present(sub'==nsub & trial_cond_aro==2))];  
end
rtv_rr_cond = rtv_nr_cond/2; 

[p,h,stat] = signrank(ecd_rr_cond(2:7,1) , ecd_rr_cond(2:7,2) ,'method','approximate'  )   % , 'tail','left'

[p,h,stat] = signrank(ecd_rr_cond(2:7,3) , ecd_rr_cond(2:7,4) ,'method','approximate'  )  % , 'tail','left'

figure, bar(median(ecd_rr_cond(2:7,3:4) ))
hold on, plot(ecd_rr_cond(2:7,3:4)' , 'LineWidth',2), title('arousal effect')
figure, bar(median(ecd_rr_cond(2:7,1:2) ))
hold on, plot(ecd_rr_cond(2:7,1:2)', 'LineWidth',2), title('discrimination effect')

[p,h,stat] = signrank(ecd_nr_present_cond(2:7,1) , ecd_nr_present_cond(2:7,2) ,'method','approximate'  )
[p,h,stat] = signrank(rtv_nr_cond(2:7,1) , rtv_nr_cond(2:7,2) ,'method','approximate'  )

