function ci=f(x,n, percent) % binci(x,n,percent) computes the Agresti-Coull confidence interval for the binomial parameter p, % at the confidence "percent" in the range 0-100, and % x is the number of successes as a row vector, n is the number of trials. z=norminv(1- (100-percent)/200); u=(x/n + z^2/2/n + z*sqrt(x/n.*(1-x/n)/n+ z^2/4/n^2) )/(1+z^2/n); l=(x/n + z^2/2/n - z*sqrt(x/n.*(1-x/n)/n + z^2/4/n^2) )/(1+z^2/n); ci=[l; u];