wald = function (x,n,alpha) { z=-qnorm(alpha/2) ; phat = x/n ; se=sqrt(phat*(1-phat)/n); c(phat-z*se,phat+z*se) } wald(x=23,n=89,alpha=.05) # Wald Interval prop.test(x=23,n=89,correct=F) # Wilson Interval agresti.coull = function (x,n,alpha) { z=-qnorm(alpha/2); ntilde = n+z^2 ; ptilde = (x+z^2/2)/ntilde ; se=sqrt(ptilde*(1-ptilde)/ntilde); c(ptilde-z*se,ptilde+z*se)} agresti.coull(x=23,n=89,alpha=.05) # Agresti-Coull Interval