clear all
close all


 disp('Caesarean Section Example')
  lw = 3; 
  set(0, 'DefaultAxesFontSize', 16);
  fs = 15;
  msize = 10;
  

infection = [1  11 0 0 28 23  8 0];
total =     [18 98 2 0 58 26 40 9];
proportion = infection./total;
noplan   =  [ 0  1 0 1  0  1  0 1];
riskfact =  [ 1  1 0 0  1  1  0 0];
antibio  =  [ 1  1 1 1  0  0  0 0];
[b,dev,stats] = glmfit([noplan' riskfact' antibio'],[infection' total'],'binomial','logit');
phat = glmval(b,[noplan' riskfact' antibio'],'logit');


pval = 1 - chi2cdf(dev, 8-4-1)   % 0.0117


figure(1)
plot(1:8, proportion,   's','MarkerSize',msize+6,...
                                          'MarkerEdgeColor','k',...
                                           'MarkerFaceColor','b')
hold on
plot(1:8, phat,  'o','MarkerSize',msize+2,...
                                          'MarkerEdgeColor','k',...
                                           'MarkerFaceColor','g')
legend('Observed Proportions','Logistic Fit',2)
%plot(1:8, logitFit,'k:', 'linewidth', lw );
axis([1 8 0 0.95])
grid on
xlabel('Code for (noplan, riskfact, antibio)')
ylabel('Probability of Infection')
print -depsc 'C:\Springer\Logistic\Logisticeps\caesarean.eps'





