> 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 = 0.05) [1] 0.1674777 0.3493762 > prop.test(x = 23, n = 89, correct = F) 1-sample proportions test without continuity correction data: 23 out of 89, null probability 0.5 X-squared = 20.7753, df = 1, p-value = 5.165e-06 alternative hypothesis: true p is not equal to 0.5 95 percent confidence interval: 0.1788154 0.3580294 sample estimates: p 0.2584270 > 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 = 0.05) [1] 0.1782826 0.3585622