%% Stroke hem_st = 43 % number of cases of hemorrhagic stroke observed in the study population tot_st = 306 % total number of cases of stroke observed in the study population study_prop = 43/306 % proportion of hemorrhagic stroke in the study population pop_prop = 0.2 % general population proportion of strokes which are hemorrhagic (as opposed to ischemic) pause xs= 1:306; bvals = binopdf(xs,306,.2); figure; plot(xs,bvals) title('Binomial distribution for 306 trials and p=0.2') ylabel('Probability of observing n successes if p=0.2') xlabel('Number of successes') % A 'success' here means you had a hemorrhagic stroke instead of a regular % ischemic one pause xlim([0,100]) % look closer at the region where the probability density is pause % Mark the rejection region alpha = 0.05; hem_st_crit = binoinv([alpha/2,1-alpha/2],tot_st,pop_prop); % Find two-tailed critical regions shade_region([-1,1],hem_st_crit,xs,bvals,binopdf(hem_st_crit,306,0.2)); hem_st_crit_lower = hem_st_crit(1) % lower critical value hem_st_crit_upper = hem_st_crit(2) % upper critical value %text(-Tcrit,tpdf(-Tcrit,df),[sprintf('T_{crit}=%0.3g\nHatched Area\n=',Tcrit), '\alpha',sprintf('=%0.3g',alpha)],'VerticalAlignment','Bottom') pause %% Where is our hemorrhagic stroke value? line([hem_st,hem_st],[0,.05],'Color','m') text(hem_st,.04,['This study\rightarrow',sprintf('\nCount= %0.3g',hem_st)],'HorizontalAlignment','right','Color','m') pause %% p-value for observing the study proportion if the true proportion is the % same as the general population stroke_p_value = sum(bvals(bvals<=bvals(hem_st))) %this is the two-tailed p_value % This is the sum of all the probabilities which are less likely than our % observed value text(hem_st,.02,sprintf('p = %0.2g',stroke_p_value),'HorizontalAlignment','right','Color','m'); % This is different for the binomial case because the distribution % is not exactly symmetrical and the probability distribution function does % not exist between integers, so in general we can't just take double the % one-tail p-value like we can for the t or normal distributions