% There are 22 subjects in a clinical trial and 9 are females.
% There are 11 portions of drug and 11 placebos. Only
% 2 females received drug.
% Are the proportions of males and females assigned to a drug
% (statistically) equal?
% That is, is the assignment of drug homogeneous wrt gender.

a = 2; b = 7; c = 9; d =4;
n=a + b + c + d;
T = a;

pval = hygecdf(T,n,a+c,a+b)              %H1: p1<p2   pval=0.0402
%pval = 1-hygecdf(T-1,n,a+c,a+b)   %H1:p1 > p2   pval=0.9962

pa = hygepdf(T,n,a+c,a+b);
for  i = 1:min(a+b, a+c)+1
    p(i) = hygepdf(i-1,n,a+c,a+b) ;
end
pval2 = sum(p(p <= pa))  %H1: p1 ~= p2  pval2=0.1179
 