% LMex040301_4th.m
% Example 4.3.1, Overbooking airline seats; Application of the normal 
% distribution and the continuity correction. Page 297 in
% Larsen & Marx (2006) Introduction to Mathematical Statistics, 4th edition
% Written by Eugene.Gallagher, http://www.es.umb.edu/edgwebp.htm
% Written Fall 2010, Revised 1/7/11
% 178 seats sold for 168 economy class seats available, p=0.9 passenger
% will show up. What is the probability that not everyone who shows up at
% the gate on time can be accomodated?
n=178;p=0.9;n2=169;
P=normcdf((n+0.5-n*p)/sqrt(n*p*(1-p)))-...
    normcdf((n2-0.5-n*p)/sqrt(n*p*(1-p)));
fprintf(...
 '\nP not all can be accomodated, with continuity correction = %6.4f.\n',P)
% Without the continuity correction:
P2=normcdf((n-n*p)/sqrt(n*p*(1-p)))-...
    normcdf((n2-n*p)/sqrt(n*p*(1-p)));
fprintf(...
'P not all can be accomodated, without continuity correction = %6.4f.\n',P2)
k=169:178;
% Solve as a binomial pdf
 P3 = sum(binopdf(k,n,p));
 fprintf(...
'P not all can be accomodated, exact binomial = %6.4f.\n',P3)
 P4 = binocdf(n,n,p)-binocdf(n2-1,n,p);
 fprintf(...
'P not all can be accomodated, exact binomial cdf = %6.4f.\n',P4)