% LMex040306_4th.m
% Example 4.3.6 Drunk driving pages 308-309 in Larsen & Marx (2006)
% Based on LMex040305_4th.m
% Larsen & Marx (2006) Introduction to Mathematical Statistics, 4th edition
% Written Fall 2010 by Eugene Gallagher for EEOS601 Revised: 1/9/11
% Eugene.Gallagher@umb.edu 
% http://alpha.es.umb.edu/faculty/edg/files/edgwebp.html
% A legally drunk driver in many states has a blood alcohol level of 0.10%,
% but the breathalyzer has measurement error. Repeated measurements
% indicate that the the estimate of the mean is unbiased and sigma is
% 0.004%
% If a driver's true blood alcohol content is 0.095%, what is the
% probability that he will be incorrectly booked on a DUI charge?
mu=0.095;
sigma=0.004;
Observed=0.1;
P=1-normcdf((Observed-mu)/sigma);
fprintf('\nThe approximate p value using the central limit theorem is ')
fprintf('%7.4f.\n',P)

% Plot Figure 4.3.5
subplot(2,1,1)
X=0.075:0.0005:0.115;
Y = normpdf(X,mu,sigma);
plot(X,Y,'--r');
axis([0.075 0.115 0 105]);title('Figure 4.3.5','FontSize',20);
ax1=gca;
xlabel('Blood Alcohol Level','FontSize',16),
ylabel('f_y(y)','FontSize',16);
ax1=gca;
set(ax1,'xtick',0.08:0.005:0.11,'FontSize',14);
set(ax1,'ytick',0:25:100,'FontSize',14)
hold on;
xf=0.1:0.0001:.115;yf=normpdf(xf,mu,sigma);
fill([0.1 xf 0.115]',[0 yf 0]',[.8 .8 1])
s=sprintf('Area = %6.4f',P)
% figure(gcf);pause
% [X1,Y1]=ginput(1);
text(.102,47.6,s,'FontSize',18);
hold off;

subplot(2,1,2)
X=-3.5:0.01:3.5;
Y = normpdf(X,0,1);
plot(X,Y,'--r');
axis([-3.55 3.55 0 0.42]);
ax1=gca;
xlabel('Z-score','FontSize',16),
ylabel('f_z(z)','FontSize',16);
ax1=gca;
set(ax1,'xtick',-3.5:0.5:3.5,'FontSize',14);
set(ax1,'ytick',0:0.2:0.4,'FontSize',14)
hold on;
xf=1.25:0.001:3.5;yf=normpdf(xf,0,1);
fill([1.25 xf 3.5]',[0 yf 0]',[.8 .8 1])
text(1.5,0.19,s,'FontSize',18);
figure(gcf);pause
% [X2,Y2]=ginput(1);
hold off;
subplot(1,1,1)