% LMex050401_4th.m
% Larsen & Marx Example 5.4.1
% Analysis of precision
% Eugene.Gallagher@umb.edu, written 10/2010, revised 3/5/11.
clear all
hold off; clf
p=0.6;n=10
P1=sum(binopdf(5:7,n,p));
fprintf('Exact P for n=%1.0f, based on binomial distribution=%7.5f.\n',n,P1)
n=100;
z1=(0.5-0.6)/sqrt(p*(1-p)/n);
z2=(0.7-0.6)/sqrt(p*(1-p)/n);
P2=normcdf(z2)-normcdf(z1);
fprintf('P, based on large-sample normal approximation=%5.3f.\n',P2);
P3=sum(binopdf(50:70,n,p));
fprintf('Exact P, based on binomial distribution=%5.3f.\n',P3)
n=10;
x=0:10;
Y=binopdf(0:10,10,p);
bar(x/10,Y,1);
axis([-.05 1.05 0 .85]);
set(get(gca,'Children'),'FaceColor',[1 1 1])
hold on
bar([.5 .6 .7],binopdf(5:7,10,p),1,'FaceColor',[0.8 1 0.8]);
figure(gcf); pause;
title('Figure 5.4.1','FontSize',22)
xlabel('Value of X/n','FontSize',20)
x=-0.05:0.01:1.05;
%y2=normpdf(x,0.6,sqrt(p*(1-p)/n));
% plot(x,y2/10,'--r','LineWidth',2)
n=100;
y3=normpdf(x,0.6,sqrt(p*(1-p)/n));
plot(x,y3/10,'--r','LineWidth',3)
xf=0.5:.001:0.7;yf=normpdf(xf,0.6,sqrt(p*(1-p)/n));
fill([0.5 xf 0.7]',[0 yf/10 0]',[0.8 0.8 1])
alpha(.5); % sets the transparency to see through.
%set(get(gca,'Children'),alpha,0.5)
figure(gcf);pause
hold off
