function [ci_1, ci_2, ci_3] = bino2ci(n, x, a, md) % This program returns the two end points of 2-sided confidence interval % [p1, p2] for unknown parameter p, X~B(n,p) % Conditions for exact C.I : 1. P(X <= x|p=p2) <= a/2, % 2. P(X >= x|p=p1) <= a/2 if nargin ~= 4 md = 0; else end % Exact 2-sided confidence interval p1 = bino_lwr(n, x, a/2); p2 = bino_upr(n, x, a/2); ci_1 = [p1 p2]; % Exact C.I. % Wald 2-sided confidence interval ci_2 = bino_wald(n, x, a); % Wilson 2-sided confidence interval ci_3 = bino_wilson(n, x, a); if md ~= 0 for k = 1 : length(x) fprintf(1, 'When n=%5.0f, x = %5.0f, and size = %3.2f\n', n,x(k,1),a); fprintf(1, '1. The exact 2-sided C.I. is [%6.5f %6.5f] \n',... ci_1(k,1), ci_1(k,2)); fprintf(1, '2. The Wald 2-sided C.I. is [%6.5f %6.5f] \n',... ci_2(k,1), ci_2(k,2)); fprintf(1, '3. The Wilsons 2-sided C.I. is [%6.5f %6.5f] \n\n',... ci_3(k,1), ci_3(k,2)); end else end