% LMcs040202_4th.m
% Case Study 4.2.2 alpha decay & Geiger counter Page 282-284 in
% Larsen & Marx (2006) Introduction to Mathematical Statistics 4th Edition
% Written by Eugene Gallagher for EEOS601
% Eugene.Gallagher@umb.edu http://www.es.umb.edu/edgwebp.htm
% Written 11/4/2010, Revised 1/7/11
% Fitting the Poisson pdf to radioactive decay: alpha-particle
k=[0:11]';
Frequency=[57 203 383 525 532 408 273 139 45 27 10 6]';
sumFrequency=sum(Frequency);
lambda=sum(k.*Frequency)./sumFrequency;
fprintf('The Poisson parameter is %5.3f\n',lambda)
ObservedP=Frequency./sumFrequency;
ExpectedP=poisspdf(k,lambda);
TableData=[k Frequency ObservedP ExpectedP]; 
fprintf('\n\t\t\t\t\tTable 4.2.3\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(57,1);ones(203,1);2*ones(383,1);3*ones(525,1);4*ones(532,1);...
    5*ones(408,1);6*ones(273,1);7*ones(139,1);8*ones(45,1);...
    9*ones(27,1);10*ones(10,1);11*ones(6,1)];
[LAMBDAHAT, LAMBDACI] = poissfit(DATA,0.05);
fprintf(...
    '\nThe Poisson parameter =%5.3f, with 95%% CI: [%5.3f %5.3f]\n\n',...
    LAMBDAHAT, LAMBDACI)