% LMex030205_4th
% Example 3.2.5 Winning at KENO with a ten-spot ticket
% Larsen & Marx (2001) 3rd edition page 130
% Larsen & Marx (2006) 4th edition page 141
% if the statitics toolbox isn't loaded with hygepdf
% calls Gallagher's m.file hypergeop.m
% N=80 numbers
% n=10 numbers selected
% r=20 number of winning numbers out of 80
% k=5  pk5 is the probability of getting
%               5 of the winning numbers
% written by E Gallagher, Eugene.Gallagher@umb.edu
% written 6/20/03; last revised 10/7/10
N=80;n=10;r=20;k=5;
if exist('hygepdf')==2
    pk5=hygepdf(k,N,r,n)
elseif  exist('hypergeop')==2
    % Gallagher's function, which calls Matlab's nchoosek.m for small N
    pk5=hypergeop(N,n,r,k)
end
fprintf('Probability of picking 5 correct = %6.4f\n',pk5);

% Optional, find the probability of winning with a 5, 6, 7 ... 10
% and plot the pdf
pkge5=sum(hygepdf(5:(min([r n])),N,n,r));
fprintf(...
    'Probability of picking 5 correct = %6.4f and 5 or more = %6.4f\n',...
    pk5,pkge5);

% Optional: plot the the full hypergeometric probability density function
% for the ten-spot ticket
p=hygepdf(0:(min([r n])),N,n,r);
bar(0:10,p,1)
set(get(gca,'Children'),'FaceColor',[.8 .8 1])
axis([-.6 10.6 0 .31])
ylabel('p_x(k)','FontSize',16),xlabel('k','FontSize',16),
title('Example 3.2.5','FontSize',20)
figure(gcf)
pause