function analyze_release_dependence(critz,pscmat,array_of_charges,trialcountmat,livetrials_preinduc,livetrials_postinduc,presentcase,casecolor,patchtitle,special_waveform_matrix_preinduc,special_waveform_matrix_postinduc) %this script is designed for looking at the nth psc or q and seeing whether its size or likelihood of success is different whether the mth event succeeded or failed on trials with a given ipi %we can consider both the stable preinduc period and the stable postinduc period, though we need to keep in mind that the postinduc period may not be stable due to ongoing change, which could invalidate the cumu hist visualization casecolor=[.2 .2 .2]; %needed due to the inclusion of failure expts RD_diary=0; markersize=5; RD_cumuhist=1; RD_cumuhist_showraw=0; RD_p_versus_p=1; use_charge_not_psc=0; which_value_is_measured=2; %which psc or q value in the train is to be displayed which_value_is_trigger=1; %which row in the criterion matrix is the trigger (e.g., for RD of the second response based on first response succ/fail, which_value_is_measured would be 2 and which_value_is_trigger would be 1) which_IPI_is_checked=1; IPI_check_value=400; %in ms livetrials=livetrials_postinduc; label_addendum='postinduction'; if RD_diary|RD_cumuhist if use_charge_not_psc parameter_vector=array_of_charges(which_value_is_measured,:); histlabel=strcat('Q',num2str(which_value_is_measured),'trigger',num2str(which_value_is_trigger),'IPI',num2str(IPI_check_value),label_addendum); else parameter_vector=pscmat(which_value_is_measured+2,:); histlabel=strcat('PSC',num2str(which_value_is_measured),'trigger',num2str(which_value_is_trigger),'IPI',num2str(IPI_check_value),label_addendum); end parameter_following_success=repmat(nan,1,length(parameter_vector));parameter_following_success(find(critz(which_value_is_trigger,:)))=parameter_vector(find(critz(which_value_is_trigger,:)));parameter_following_success(find(pscmat(which_IPI_is_checked,:)~=IPI_check_value))=nan;%parameter_following_success(find(~critz(which_value_is_measured,:)))=nan; parameter_following_failure=repmat(nan,1,length(parameter_vector));parameter_following_failure(find(~critz(which_value_is_trigger,:)))=parameter_vector(find(~critz(which_value_is_trigger,:)));parameter_following_failure(find(pscmat(which_IPI_is_checked,:)~=IPI_check_value))=nan;%parameter_following_failure(find(~critz(which_value_is_measured,:)))=nan; end if RD_diary figure(presentcase+200),hold on plot(pscmat(3,:),'^','markerfacecolor','k','markeredgecolor','k','markersize',markersize) %psc always used here plot(parameter_following_success,'d','markerfacecolor','g','markeredgecolor','g','markersize',markersize) plot(parameter_following_failure,'d','markeredgecolor','r','markerfacecolor','r','markersize',markersize) plot([trialcountmat(1)+.5 trialcountmat(1)+.5],[0 max([parameter_following_success(find(~isnan(parameter_following_success))) parameter_following_failure(find(~isnan(parameter_following_failure)))])],'r','linewidth',2) title(num2str(presentcase)) end if RD_cumuhist if any(~isnan(parameter_following_success))&&any(~isnan(parameter_following_failure)) figure(presentcase+300),hold on [x_for_ecdf_firstpulsesucceed,y_for_ecdf_firstpulsesucceed]=cumulative_histogram(parameter_following_success(livetrials),'g'); [x_for_ecdf_firstpulsefail,y_for_ecdf_firstpulsefail]=cumulative_histogram(parameter_following_failure(livetrials),'r:'); [h,p]=kstest2(parameter_following_success,parameter_following_failure) ylabel(strcat('KS p:',num2str(p))) set(findobj('type','line'),'color','k','linewidth',.5) set(gca,'ytick',[0 1]),xlabel(histlabel) title(patchtitle) if RD_cumuhist_showraw forposselec=critz(which_value_is_trigger,livetrials); forposselec(find(pscmat(which_IPI_is_checked,livetrials)~=IPI_check_value))=0; fornegselec=critz(which_value_is_trigger,livetrials); fornegselec(find(pscmat(which_IPI_is_checked,livetrials)~=IPI_check_value))=1; positive_selection_waveforms=special_waveform_matrix_preinduc(:,find(forposselec))';negative_selection_waveforms=special_waveform_matrix_preinduc(:,find(~fornegselec))'; figure(400+presentcase),hold on,for iii=1:size(positive_selection_waveforms,1),plot(positive_selection_waveforms(iii,:),'color',casecolor,'linewidth',.2),end figure(500+presentcase),hold on,for jjj=1:size(negative_selection_waveforms,1),plot(negative_selection_waveforms(jjj,:),'color',casecolor,'linewidth',.2),end end end end if RD_p_versus_p trig=critz(which_value_is_trigger,livetrials); meas=critz(which_value_is_measured,livetrials); trig(find(pscmat(which_IPI_is_checked,livetrials)~=IPI_check_value))=[]; meas(find(pscmat(which_IPI_is_checked,livetrials)~=IPI_check_value))=[]; probability_label=strcat('meas:',num2str(which_value_is_measured),'trig:',num2str(which_value_is_trigger),'IPI:',num2str(IPI_check_value),label_addendum); if ~isempty(trig) meas_succ_count_when_trig_succ=length(find(meas(find(trig)))); trig_succ_count=length(find(trig)); meas_succ_count_when_trig_fail=length(find(meas(find(~trig)))); trig_fail_count=length(find(~trig)); prop_meas_succ_when_trig_succ=meas_succ_count_when_trig_succ/trig_succ_count;prop_meas_succ_when_trig_fail=meas_succ_count_when_trig_fail/trig_fail_count; [upperlimsuccess_trigontrig,lowerlimsuccess_trigontrig]=agresti_coull_binomial_confidence_interval(meas_succ_count_when_trig_succ,trig_succ_count); [upperlimfailure_trigontrig,lowerlimfailure_trigontrig]=agresti_coull_binomial_confidence_interval(meas_succ_count_when_trig_fail,trig_fail_count); trig_succ_count_when_meas_succ=length(find(trig(find(meas)))); meas_succ_count=length(find(meas)); trig_succ_count_when_meas_fail=length(find(trig(find(~meas)))); meas_fail_count=length(find(~meas)); prop_trig_succ_when_meas_succ=trig_succ_count_when_meas_succ/meas_succ_count;prop_trig_succ_when_meas_fail=trig_succ_count_when_meas_fail/meas_fail_count; [upperlimsuccess_trigonmeas,lowerlimsuccess_trigonmeas]=agresti_coull_binomial_confidence_interval(trig_succ_count_when_meas_succ,meas_succ_count); [upperlimfailure_trigonmeas,lowerlimfailure_trigonmeas]=agresti_coull_binomial_confidence_interval(trig_succ_count_when_meas_fail,meas_fail_count); figure(600+presentcase),rung_plotter_asymm_intervals(prop_meas_succ_when_trig_succ,upperlimsuccess_trigontrig,lowerlimsuccess_trigontrig,prop_meas_succ_when_trig_fail,upperlimfailure_trigontrig,lowerlimfailure_trigontrig,[.2 1 .2],.1) hold on, rung_plotter_asymm_intervals(prop_trig_succ_when_meas_succ,upperlimsuccess_trigonmeas,lowerlimsuccess_trigonmeas,prop_trig_succ_when_meas_fail,upperlimfailure_trigonmeas,lowerlimfailure_trigonmeas,[.2 .2 1],.2) xlabel(probability_label) if ~isnan(prop_meas_succ_when_trig_succ) & ~isnan(prop_trig_succ_when_meas_succ) & ~isnan(prop_meas_succ_when_trig_fail) & ~isnan(prop_trig_succ_when_meas_fail)... & prop_meas_succ_when_trig_succ & prop_trig_succ_when_meas_succ & prop_meas_succ_when_trig_fail & prop_trig_succ_when_meas_fail figure(700+presentcase),rectangles_with_error_bars([prop_meas_succ_when_trig_succ prop_trig_succ_when_meas_succ;prop_meas_succ_when_trig_fail prop_trig_succ_when_meas_fail],... [upperlimsuccess_trigontrig upperlimsuccess_trigonmeas;upperlimfailure_trigontrig upperlimfailure_trigonmeas],[lowerlimsuccess_trigontrig lowerlimsuccess_trigonmeas;lowerlimfailure_trigontrig... lowerlimfailure_trigonmeas], [.2 1 .2;.2 .2 1]',1) xlabel(probability_label) end end end