function exam3_6
%example 3.6
%8/30/2007 by Changxing Ma

nnn=[38     2     2     5    11     1    10    31];

n00=nnn(1)+nnn(8);
n01=nnn(2)+nnn(7);
n10=nnn(4)+nnn(5);
n11=nnn(3)+nnn(6);
nn=[n00 n01 n10 n11];
n=sum(nn);

rAB=(n10 + n11)/n                                                                    
rBC=(n01 + n11)/n                                                                    
rAC=(n01 + n10)/n                                                                    
                                                                                     
LABC=(n00+n01)*log(1-rAB)+(n00+n10)*log(1-rBC)+(n10+n11)*log(rAB)+(n01+n11)*log(rBC) 
LACB=(n00+n11)*log(1-rAC)+(n00+n10)*log(1-rBC)+(n01+n10)*log(rAC)+(n01+n11)*log(rBC) 
LBAC=(n00+n01)*log(1-rAB)+(n00+n11)*log(1-rAC)+(n10+n11)*log(rAB)+(n01+n10)*log(rAC) 

sprintf('(%d+%d)\\log(1-%4.2f)+(%d+%d)\\log(1-%4.2f)\\\\&&+(%d+%d)\\log(%4.2f)+(%d+%d)\\log(%4.2f)=%7.2f',...
   [n00 n01 rAB n00 n10 rBC n10 n11 rAB n01 n11 rBC LABC]) 
sprintf('(%d+%d)\\log(1-%4.2f)+(%d+%d)\\log(1-%4.2f)\\\\&&+(%d+%d)\\log(%4.2f)+(%d+%d)\\log(%4.2f)=%7.2f',...
   [n00 n11 rAC n00 n10 rBC n01 n10 rAC n01 n11 rBC LACB]) 
sprintf('(%d+%d)\\log(1-%4.2f)+(%d+%d)\\log(1-%4.2f)\\\\&&+(%d+%d)\\log(%4.2f)+(%d+%d)\\log(%4.2f)=%7.2f',...
   [n00 n01 rAB n00 n11 rAC n10 n11 rAB n01 n10 rAC LBAC]) 

1/(1+exp(LACB-LABC)+exp(LBAC-LABC))
