% LMcs040203_4th.m
% Fitting football fumbles to a Poisson pdf
% From Larsen & Marx (2006) Introduction to Mathematical Statistics
% 4th edition.
% Written by Eugene.Gallagher@umb.edu
% Revised 11/4/2010
% See LMcs040202_4th.m (alpha decay) for a very similar program
k=[0:7]';
Frequency=[8 24 27 20 17 10 3 1]';
sumFrequency=sum(Frequency);
meank=sum(k.*Frequency)./sumFrequency;
fprintf('The Poisson parameter is %5.3f\n',meank)
ObservedP=Frequency./sumFrequency;
ExpectedP=Poisspdf(k,meank);
TableData=[k Frequency ObservedP ExpectedP]; 
fprintf('\n\t\t\t\t\tTable 4.2.5\n')
fprintf('No. Detected, k \tFrequency \tProportion \tp_x(k)\n')
fprintf('   %2.0f\t\t\t\t%2.0f\t\t\t%5.3f\t\t%5.3f\n',TableData');

% Using concepts from Chapter 5, a MLE fit could be made of the data:
% The only new feature added is a 95% CI for the binomial parameter.
% See LMcs050201_4th.m for another example of using Poisspdf to fit
% the Poisson distribution to data
%
DATA=[zeros(8,1);ones(24,1);2*ones(27,1);3*ones(20,1);4*ones(17,1);...
    5*ones(10,1);6*ones(3,1);7];
[LAMBDAHAT, LAMBDACI] = poissfit(DATA,0.05);
fprintf(...
    '\nThe Poisson parameter =%5.3f, with 95%% CI: [%5.3f %5.3f]\n\n',...
    LAMBDAHAT, LAMBDACI)
