%This example is taken from Table 3 of Crowder (1978),
%and concerns the proportion of seeds that germinated
%on each of N=21 plates arranged according to a 2 by 2 factorial 
%layout by seed and type of root extract.   The data are listed
%below, where 'germinated' and 'platetot' are the number of germinated and the 
%total number of seeds on the i th plate, i =1,...,N. 

% There are two types of seed  (0 = O. aegyptiaco 75, 1 = O. aegyptiaco 73)
% and two root extract types (0 = bean, 1 = cucumber)

%These data are also analysed by Breslow: and Clayton (1993). 


clear all
close all


 disp('Seeds Additive Model Example')
  lw = 3; 
  set(0, 'DefaultAxesFontSize', 16);
  fs = 15;
  msize = 10;
  



germinated = [10, 23, 23, 26, 17, 5, 53, 55, 32, 46, 10,   8, 10,   8, 23, 0,  3, 22, 15, 32, 3];
platetot =  [39, 62, 81, 51, 39, 6, 74, 72, 51, 79, 13, 16, 30, 28, 45, 4, 12, 41, 30, 51, 7];
oa73 =  [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1];
cucum = [0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1];

[logitCoef,dev] = glmfit([oa73' cucum'],[germinated' platetot'],'binomial','logit');
logitFit = glmval(logitCoef,[[0 0 1 1]'  [0 1 0 1]'],'logit');

logitCoef

dev

g00 = sum(germinated(oa73==0 & cucum==0)); t00 = sum(platetot(oa73==0 & cucum==0));
g01 = sum(germinated(oa73==0 & cucum==1)); t01 = sum(platetot(oa73==0 & cucum==1));
g10 = sum(germinated(oa73==1 & cucum==0)); t10 = sum(platetot(oa73==1 & cucum==0));
g11 = sum(germinated(oa73==1 & cucum==1)); t11 = sum(platetot(oa73==1 & cucum==1));

figure(1)
plot(1:4, [g00/t00 g01/t01 g10/t10  g11/t11] ,'rs', 'markersize', msize );
hold on
plot(1:4, [g00/t00 g01/t01 g10/t10  g11/t11] ,'r:', 'linewidth', lw );
plot(1:4, logitFit,'ko', 'markersize', msize );
plot(1:4, logitFit,'k:', 'linewidth', lw );
axis tight