% LMcs100503_4th.m
% Larsen & Marx (2006) Introduction to Mathematical Statistics, 4th Edition
% Page 635-637
% An example of a 2x2 contingincy table
% Analyzed using Anders Holsberg's contincy.m & fishertest.m (Matlab 
% Central)
% Written by Eugene.Gallagher@umb.edu, Written 11/21/10
% Place the data in a 2 x 2 table:
observed=[7 4;3 11]
[p,chi2,expected] = contincy(observed, 'chi2')
[r,c]=size(observed);df=(r-1)*(c-1);
criticalval=chi2inv(.95,df)
if chi2>criticalval
    disp('Reject Ho')
else
    disp('Fail to reject Ho')
end
[H,P, STATS] = fishertest(observed, 0.05)
% If analyzed with the two-sample binomial, p values the same as chi^2
% z = sqrt(chi2)
[D,phat,z,pvalue,CI]=binom2sample(7,11,3,14,0.05)