% HORSE KICKS

close all
clear all

 disp('Goodness of Fit: Horse Kick Problem')
 lw = 2.5; 
 set(0, 'DefaultAxesFontSize', 16);
 fs = 15;
 msize = 10;


% observed freq
ni = [109 65 22 3 1]
 
% estimate Poisson lambda. The MLE is  Xbar
% 0 * 109 + 1 * 65 + 2* 22 + 3*3 + 4*1 = 122
% lambda =122/200 = 0.61
npi = 200 * [poisspdf(0:3, 0.61)  1-poisscdf(3, 0.61)]


ch2 = sum( (ni-npi).^2 ./npi )

%ch2 = 0.5999

%pvalue
1-chi2cdf(0.5999, 5-1-1)
%ans = 0.8965
%
% critical value
chi2inv(0.95, 5-1-1)
%ans = 7.8147
%rejection region (7.8147, infinity)

