
clear all
close all
%
disp('Coverage Probability by Wald Interval')
  lw = 2; 
  set(0, 'DefaultAxesFontSize', 16);
  fs = 15;
  msize = 10;
% end of preabmle--------------------------------------

n = 20;  %sample
alpha = 0.05; %confidence 1-alpha
M=100000;
covs1=[]; 
range = 0.05:0.01:0.95;
for p=range
        X = binornd(n, p, [1 M]);
        phat = X/n; qhat = 1- phat;
    cov1 =  p < phat + norminv(1-alpha/2) * sqrt(phat .*qhat/n) & ...
                  p > phat - norminv(1-alpha/2) * sqrt(phat .* qhat/n) ;
    covs1=[covs1 sum(cov1)/M];
end
figure(1)
plot(range, covs1, 'linewidth', 2)
hold on
plot(range, covs1, 'o')
plot(0.00:0.01:1, (1-alpha)*ones(1,101), 'r-','linewidth',3)
 xlabel('p'); ylabel('coverage');
%   print -depsc 'C:\Springer\Estim\Estimeps\Waldcover.eps'