%LMFig060601_4th.m
% Also plots Figure 6.6.2
% Based on LMFig060405_4th.m
% LMFig060405_4th.m
% Using as a model %LMcs030201_4th.m, page 450 in
% Larsen & Marx (2006) Introduction to Mathematical Statistics, 4th edition
% Written 3/10/11 (11:22 -11:57 am, )
% Eugene.Gallagher@umb.edu for EEOS601 UMASS/Boston
xmin=25;xmax=27.1;mu=25;
X=mu:0.005:xmax;
sigmaj=2.4;n=30;alpha=0.05;
K = menu('Choose a graph','Figure 6.6.1','Figure 6.6.2')
CritVal=norminv(1-alpha,mu,sigmaj/sqrt(n));
Power =1-normcdf(CritVal,X,sigmaj/sqrt(n));
x=[25.75 26.8];
Pow=1-normcdf(CritVal,x,sigmaj/sqrt(n));
plot(X,Power,'--k','LineWidth',3)
axis([xmin xmax 0, 1.1])
ylabel ('Power = 1 - \beta','FontSize',20);
xlabel('Presumed value for \mu','FontSize',20)
hold on
if K==1
    % This plots horizontal and vertical lines on the graph
    plot([mu mu]',[0 1]','k','LineWidth',2)
    plot([x(1) x(1);mu x(1);x(2) x(2);mu x(2)]',[0 Pow(1);...
    Pow(1) Pow(1);0 Pow(2);Pow(2) Pow(2)]','--m','LineWidth',3);
    title('Figure 6.6.1','FontSize',22)
    t1=sprintf('Power = %6.4f',Pow(1));
    t2=sprintf('Power = %6.4f',Pow(2));
    text(mu+0.1,Pow(1)+.03,t1,'FontSize',18);
    text(mu+0.1,Pow(2)+.03,t2,'FontSize',18);
    set(gca,'Xtick',[23:0.5:25.5 x(1) 26 26.5 x(2) 27],'Ytick',[0:.25:1],'FontSize',18)
else
    n2=60;n3=900;
    CritVal2=norminv(1-alpha,mu,sigmaj/sqrt(n2));
    CritVal3=norminv(1-alpha,mu,sigmaj/sqrt(n3));
    Power2 =1-normcdf(CritVal2,X,sigmaj/sqrt(n2));
    Power3 =1-normcdf(CritVal3,X,sigmaj/sqrt(n3));
    Pow2=1-normcdf(CritVal2,x,sigmaj/sqrt(n2));
    Pow3=1-normcdf(CritVal3,x,sigmaj/sqrt(n3));
    plot(X,Power2,'--m','LineWidth',3)
    plot(X,Power3,'--c','LineWidth',3)
    title('Figure 6.6.2')
    t1=sprintf('(n=%2.0f)',n);
    t2=sprintf('(n=%2.0f)',n2);
    t3=sprintf('(n=%3.0f)',n3)
    text(25.9,0.6,t1,'FontSize',18);
    text(25.5,0.7,t2,'FontSize',18);
    text(25.1,1.03,t3,'FontSize',18);
    set(gca,'Xtick',[23:0.25:27],'Ytick',[0:.25:1],'FontSize',18)
    grid
end
figure(gcf)
pause
hold off