clear all
close all
    disp('Poisson Means')
    set(0, 'DefaultAxesFontSize', 16);
    lw =2.5;  fs = 16;  msize = 10;



ncells =  [1 6 4 2 3 8 2  5 5 9 2 7  2 3 0 2 1 4 5 2]';
agent =   [1 1 1 1 1 1 1  2 2 2 2 2  3 3 3 3 3 3 3 3]';  
ncells1=ncells(agent==1)
ncells2=ncells(agent==2)
ncells3=ncells(agent==3)

k = 3;
n1 = length(ncells1); n2 = length(ncells2); n3= length(ncells3);
ni=[n1 n2 n3]    %7     5     8
O1 = sum(ncells1); O2 = sum(ncells2); O3 = sum(ncells3);
Oi=[O1  O2  O3]  %26    28    19
N = sum(ni) %20
O = sum(Oi) %73
Ei = O .* ni/N  %25.55    18.25    29.2 
chi2 = sum( (Oi - Ei).^2 ./ Ei )  %8.7798
G2 = 2 * sum( Oi .* log(Oi./Ei ) )  %8.5484
pvalchi = 1 - chi2cdf(chi2, k-1) %0.0124
pvalG2 = 1 - chi2cdf(G2, k-1) %0.0139

% If the problem is treated as ANOVA
[panova table] = anova1(ncells, agent)

% panova = 0.0615
% table = 
%     'Source'  'SS'        'df'  'MS'       'F'       'Prob>F'
%     'Groups'  [ 32.0464]  [ 2]  [16.0232]  [3.3016]  [0.0615]
%     'Error'   [ 82.5036]  [17]  [ 4.8532]        []        []
%     'Total'   [114.5500]  [19]         []        []        []

