% LMcs050201_4th.m
% An example of MLE Poisson fitting
% Written by Eugene.Gallagher@umb.edu 10/29/10, revised 3/3/11
% Solution of Larsen & Marx Example 5.2.1
% Larsen & Marx (2006) Introduction to Mathematical Statistics, 4th Edition
% Page 352-353
% Requires the statistics toolbox
%
X=[zeros(237,1);ones(90,1);2*ones(22,1);3*ones(7,1)];
[LAMBDAHAT, LAMBDACI] = poissfit(X)
fprintf(...
'The MLE estimate of lambda is %5.3f with 95%% CI: [%5.3f %5.3f]\n',...
LAMBDAHAT,LAMBDACI)
OF=[237 90 22 7];
k=[0:3];
EF=sum(OF)*poisspdf(k,LAMBDAHAT);
% Change the 4th category pdf for k=3, to pdf for k=3:inf;
EF(4)=EF(4)+(356-sum(EF));
% Print tabular output
s=['0 ';'1 ';'2 ';'3+'];
D=num2str([OF' EF']);
fprintf('\n                     Table 5.2.1\n')
fprintf('                            Observed  Expected\n')
fprintf('Number of Major Changes    Frequency Frequency\n')
disp([repmat(' ',4,10) s repmat(' ',4,17) D])
% Plot the data using Case Study 3.3.1 as a model
h1=bar(0:3,[OF;EF]',1,'grouped')
legend('Observed','Poisson Expectation','NorthEast','FontSize',20)
xlabel('Number of Major Changes','FontSize',20)
ylabel('Frequency','FontSize',20)
s=sprintf('Case Study 5.2.1, lambda=%6.4f',LAMBDAHAT);
title(s,'FontSize',22);figure(gcf);