function analyze_mean_responses_using_precisely_measured_charge(beflive,aflive,critz,array_of_charges,casecolor,x_offset)
%takes the charge values from careful charge calculator, finds the mean and confidence interval before and after induction, plots the mean and error bar
%checked aug 6, 2007
%note -- only q_o is considered from each trial

figaddon=70;

preinduction_criteria=critz(1,beflive);postinduction_criteria=critz(1,aflive);
charges_antes=array_of_charges(1,beflive);charges_despues=array_of_charges(1,aflive);
charges_succ_antes=charges_antes(find(preinduction_criteria));charges_succ_despues=charges_despues(find(postinduction_criteria));
charges_fail_antes=charges_antes(find(~preinduction_criteria));;charges_fail_despues=charges_despues(find(~postinduction_criteria));
    figure(1+figaddon),subplot(3,3,[2 5 8]),set(gcf,'position',[145   120   278   707])   %plots mean of all q_o (success and failure) with SEM
meanbefore=mean(charges_antes);stdbefore=std(charges_antes);sembefore=stdbefore/sqrt(length(charges_antes));
meanafter=mean(charges_despues);stdafter=std(charges_despues);semafter=stdafter/sqrt(length(charges_despues));
rung_plotter(meanbefore,meanafter,sembefore,semafter,casecolor,x_offset)
hold on, title('Q_o')
    figure(2+figaddon),subplot(3,3,[2 5 8]),set(gcf,'position',[445   120   278   707])   %plots mean of q_o success only with SEM
meansuccbefore=mean(charges_succ_antes);stdsuccbefore=std(charges_succ_antes);semsuccbefore=stdsuccbefore/sqrt(length(charges_succ_antes));
meansuccafter=mean(charges_succ_despues);stdsuccafter=std(charges_succ_despues);semsuccafter=stdsuccafter/sqrt(length(charges_succ_despues));
rung_plotter(meansuccbefore,meansuccafter,semsuccbefore,semsuccafter,casecolor,x_offset)
hold on, title('Q_o, success trials')
    figure(3+figaddon),subplot(3,3,[2 5 8]),set(gcf,'position',[745   120   278   707])   %plots number of successes of event_o with binomial confidence interval
numsuccantes=length(charges_succ_antes);      numtrialsantes=length(beflive);
numsuccdespues=length(charges_succ_despues);     numtrialsdespues=length(aflive);
succpropantes=numsuccantes/numtrialsantes;succpropdespues=numsuccdespues/numtrialsdespues;
[upperlimbefore,lowerlimbefore]=agresti_coull_binomial_confidence_interval(numsuccantes,numtrialsantes);
[upperlimafter,lowerlimafter]=agresti_coull_binomial_confidence_interval(numsuccdespues,numtrialsdespues);
rung_plotter_asymm_intervals(succpropantes,upperlimbefore,lowerlimbefore,succpropdespues,upperlimafter,lowerlimafter,casecolor,x_offset)
hold on, title('number of successes')
    figure(4+figaddon),subplot(3,3,[2 5 8]),set(gcf,'position',[1045   120   278   707])  %plots mean of q_o failure only with SEM
meanfailbefore=mean(charges_fail_antes);stdfailbefore=std(charges_fail_antes);semfailbefore=stdfailbefore/sqrt(length(charges_fail_antes));
meanfailafter=mean(charges_fail_despues);stdfailafter=std(charges_fail_despues);semfailafter=stdfailafter/sqrt(length(charges_fail_despues));
rung_plotter(meanfailbefore,meanfailafter,semfailbefore,semfailafter,casecolor,x_offset)
hold on, title('Q_o, failure trials')