I think what you want is a confidence interval for a proportion. How to calculate a confidence interval for a proportion is an astonishingly controversial matter and there are many different approaches. The Wikipedia page lists several of those approaches.
In their paper, Agresti and Coull show that what they call the score confidence interval performs well, even when the sample size is small. The paper from Brown et al. (2001) Interval estimation for a binomial proportion calls it the Wilson interval because it was first introduced by Edwin Bidwell Wilson in his paper in 1927. In addition, the confidence interval has the convenient property that the endpoints are always within 0 and 100% which is not the case for the much-used Wald confidence interval.
In summary (thanks to @NickCox): the normal approximation (Wald interval) is often inappropriate and other approaches should be used, such as the Wilson interval. For other valid alternatives consult the paper of Brown et al. (2001).
The $100(1-\alpha)\%$ Wilson confidence interval can be calculated as follows:
$$
\begin{align}
\mathrm{UL} &= \frac{\hat{p}+\frac{z_{1-\alpha/2}^{2}}{2n}+z_{1-\alpha/2}\sqrt{\frac{\hat{p}(1-\hat{p})}{n}+\frac{z_{1-\alpha/2}^{2}}{4n^{2}}}}{1+\frac{z_{1-\alpha/2}^{2}}{n}} \\
\mathrm{LL} &= \frac{\hat{p}+\frac{z_{\alpha/2}^{2}}{2n}+z_{\alpha/2}\sqrt{\frac{\hat{p}(1-\hat{p})}{n}+\frac{z_{\alpha/2}^{2}}{4n^{2}}}}{1+\frac{z_{\alpha/2}^{2}}{n}} \\
\end{align}
$$
Here $\mathrm{UL}$ denotes the upper limit and $\mathrm{LL}$ the lower limit of the confidence interval; $\hat{p}$ is the proportion of your sample (0.3 in your case); $n$ the sample size (100 in your case); $z_{1-\alpha/2}$ is the $(1-\alpha/2)$-quantile of the standard normal distribution. For a 95%-CI, this is about $1.96$ ($z_{\alpha/2}\approx -1.96$ because of the symmetry of the normal distribution).
In your case, the 95% Wilson confidence interval for a proportion of 0.3 with a sample size of 100 is $[0.219, 0.396]$.
Here is an R
script that calculates the (modified) Wilson confidence interval for any given $n$ and $\hat{p}$ (x
is the number of successes out of n
). Even more convenient is the R
package binom which provides the function binom.confint
which calculates the confidence interval using 11 different methods (the Wilson interval is included).
n <- 100
x <- 30
alpha <- 0.05
p.hat <- x/n
upper.lim <- (p.hat + (qnorm(1-(alpha/2))^2/(2*n)) + qnorm(1-(alpha/2)) *
sqrt(((p.hat*(1-p.hat))/n) + (qnorm(1-(alpha/2))^2/(4*n^2))))/
(1 + (qnorm(1-(alpha/2))^2/(n)))
lower.lim <- (p.hat + (qnorm(alpha/2)^2/(2*n)) + qnorm(alpha/2) *
sqrt(((p.hat*(1-p.hat))/n) + (qnorm(alpha/2)^2/(4*n^2))))/
(1 + (qnorm(alpha/2)^2/(n)))
#==============================================================================
# Modification for probabilities close to boundaries
#==============================================================================
if ((n <= 50 & x %in% c(1, 2)) | (n >= 51 & n <= 100 & x %in% c(1:3))) {
lower.lim <- 0.5 * qchisq(alpha, 2 * x)/n
}
if ((n <= 50 & x %in% c(n - 1, n - 2)) | (n >= 51 & n <= 100 & x %in% c(n - (1:3)))) {
upper.lim <- 1 - 0.5 * qchisq(alpha, 2 * (n - x))/n
}
lower.lim
[1] 0.2189489
upper.lim
[1] 0.3958485
#==============================================================================
# Using the package "binom"
#==============================================================================
library(binom)
binom.confint(x=30, n=100, conf.level=0.95)
method x n mean lower upper
1 agresti-coull 30 100 0.3000000 0.2186514 0.3961460
2 asymptotic 30 100 0.3000000 0.2101832 0.3898168
3 bayes 30 100 0.3019802 0.2168414 0.3945465
4 cloglog 30 100 0.3000000 0.2135522 0.3910559
5 exact 30 100 0.3000000 0.2124064 0.3998147
6 logit 30 100 0.3000000 0.2184030 0.3966128
7 probit 30 100 0.3000000 0.2168949 0.3950896
8 profile 30 100 0.3000000 0.2160309 0.3940967
9 lrt 30 100 0.3000000 0.2159984 0.3941141
10 prop.test 30 100 0.3000000 0.2145426 0.4010604
11 wilson 30 100 0.3000000 0.2189489 0.3958485