Confidence Intervals for Proportions in R and Excel

Suppose one conducts a survey of $n = 120$ people and $81$ of them say that they will vote in the next election. Equivalently, of the $120$ surveyed, the proportion that said they would vote in the next election is $\widehat{p} = 0.675$.

Noting that the requisite assumptions seem to be satisfied, as $81 \ge 5$ and $120 - 81 = 39 \ge 5$. Thus, we know that a $95\%$ confidence interval for the proportion of people that will vote in the next election has bounds $$\widehat{p} \pm z_{\alpha/2} \sqrt{\frac{\widehat{p}\widehat{q}}{n}}$$ We can quickly compute these bounds with either R or Excel.

In R, we can use something similar to:

> p.hat = 81/120
> n = 120
> p.hat + c(-1,1)*qnorm(0.975)*sqrt(p.hat*(1-p.hat)/n)
[1] 0.5911986 0.7588014

In Excel, we instead can use the following two similar formulas: