We create functions that will enable us to obtain confidence intervals of the desired size:

- Create a function for obtaining the confidence intervals of the proportion from a binomial distribution with the following function:The arguments of the functions are
binom_CI = function(x, n, alpha) { phat = x/n ll=phat-qnorm(alpha/2,lower.tail=FALSE)*sqrt(phat*(1-phat)/n) ul=phat+qnorm(alpha/2,lower.tail=FALSE)*sqrt(phat*(1-phat)/n) return(paste("The ", 100*(1-alpha),"% Confidence Interval for Binomial Proportion is (", round(ll,4),",", round(ul,4),")", sep='')) }

`x`

,`n`

, and`alpha`

. That is, the user of the function needs to specify the`x`

number of success out of the`n`

Bernoulli trials, and the significance level

Start Free Trial

No credit card required