# Breaking down Wald CI, Wilson CI, and Agresti-Coull CI

I'm supposed to be writing R functions to calculate the Wald CI, Wilson CI, and Agresti-Coull CI for binomial proportion, I have a source that provides the equations, but I am completely lost. I am looking at the equations, but have no clue where I am supposed to be getting all the values I need.

Ward CI = $p̂ ± k n^{-1/2} (p̂q̂)^{1/2}$

Wilson CI = $(X+k^2/2)/(n+k^2)±(kn^{1/2})/(n+k^2)((p̂q̂+k^2)/(4n))^{1/2}$

Agresti-Coull CI = $p̂ ± k(p̂q̂)^{1/2}n̂^{1/2}$

I'm pretty sure I have most of it, but I am can't figure out what the value of k is. n=40 p = 0.2 alpha=0.05 q=0.8 These formulas are from http://projecteuclid.org/download/pdf_1/euclid.ss/1009213286 I was wondering if anyone could break these down and explain them to me?

• Where did you get the formulas? From something like this? en.wikipedia.org/wiki/Binomial_proportion_confidence_interval – Glen_b Oct 17 '16 at 1:55
• The formulas were from formulas 1, 4 , and 5 in this article projecteuclid.org/download/pdf_1/euclid.ss/1009213286 – Jamie Leigh Oct 17 '16 at 1:58
• The article defines the terms (like $\hat{p}$ and $n$) that it uses! – Glen_b Oct 17 '16 at 1:59
• The one I am really struggling with is K, it says k=Z(alpha/2) but how do I get Z? – Jamie Leigh Oct 17 '16 at 2:04
• The article defines $z$ also -- right before equation 1 it says $\kappa=z_{\alpha/2}=\Phi^{-1}(1-\alpha/2)$ – Glen_b Oct 17 '16 at 2:06

$X$ is the number of successes. $n$ is the number of trials. $\hat{p}=X/n$. $\hat{q}=1-\hat{p}$.

The article defines $\kappa$ in terms of $z$ and in turn defines $z$ right before equation 1:

$\kappa=z_{\alpha/2}=\Phi^{-1}(1-\alpha/2)$

$\Phi$ is the standard normal cdf.

$\Phi^{-1}$ is the inverse function of the standard normal cdf.

$\Phi^{-1}(1-\alpha/2)$ is the $1-\alpha/2$ upper tail quantile of the normal distribution.

For example for a 95% CI, $1-\alpha=0.95$ so $1-\alpha/2=0.975$ and $\Phi^{-1}(1-\alpha/2)\approx 1.96$.

In the article the Agresti-Coull interval is defined in terms of $\tilde{p}$ not $\hat{p}$. However, $\tilde{p}$ is of the same form as $\hat p$ but with an additional $\kappa^2/2$ successes and an additional $\kappa^2/2$ failures. For $\alpha=0.05$ that adds just under $2$ to $X$ and just under $4$ to $n$.

I think that covers all of the terms in equations 1, 4 and 5.

• I'm still not sure what the Φ is or how to calculate that. Is it a standard from a table? – Jamie Leigh Oct 17 '16 at 2:14
• @Jamie If you're working by hand you'd use normal tables. If you're on a computer you call a standard function to evaluate it. Suitable statistical/mathematical function libraries will either offer $Φ$ and $Φ^{-1}$ or the error function ($\text{erf}$) and its inverse from which $Φ$ and $Φ^{-1}$ are readily calculated. In R $Φ$ and $Φ^{-1}$ are given by pnorm and qnorm respectively. Try qnorm(0.975). See ?Distributions for a list of links to the various distributions in vanilla R for which the d,p,q and r functions work. – Glen_b Oct 17 '16 at 2:21