# Sample size calculation for a single proportion Without Any Comparisons (descriptive only): How to determine the margin of error in the formula?

I want to calculate the sample size for a single proportion (the prevalence of a disease). I know the formula and all: n = (z/m)^2 * P(1-P), where z is 1.96 (for 95% confidence level) and P stands for the prevalence of the disease in the pilot study.

In the above formula, m is supposed to be the margin of error (I have seen some sources call it d too). Anyways I have heard that m (or d) should be about 0.1 of the P estimated by the pilot study... However, I am seeing sources in which the author changes m at will. For example, this one. I just wonder if this rule is valid (that d should be 0.1 of P)? Or are there any other rules for estimating m (or d)?

## 1 Answer

Deciding on M will probably depend on the context. Increasing your sample size comes at some cost (otherwise you would just use the entire population). You need to weigh that cost against the cost of getting a wrong answer, which becomes increasingly likely with lower levels of precision in your estimate. A way to help think about this is to attach different decisions you might make depending on what estimate of P you find. In the extreme let's say you would do something radically different if P = .51 than if P = .49. In this case, you would want a very precise answer.

But at the very least you could plot M as a function of sample size and proportion to get some idea of the possibilities. In R...

power <- list()
i <- 1

for (p in seq(.01, .99, .01)){   # Proportions
for (n in seq(5, 1000, 5)){    # Sample sizes

m <- (1.96) * (sqrt((p * (1 - p))/n))   # Solve for m

power[[i]] <- c(p, n, m) # Stick it all in a list

i <- i + 1
}
}

power           <- as.data.frame(t(do.call(cbind, power))) # Convert list to useful DF
colnames(power) <- c("P", "N", "M")

library(ggplot2)

ggplot(power, aes(x = P, y = N, fill = M, z = M)) +    # Level plot with ggplot2
geom_tile() +
stat_contour(breaks = c(.1)) + # Use contour to identify level(s) of M you might want
ylab("Sample Size") +
xlab("Proportion") +
scale_fill_gradient(name = "ME", limits = c(0, .45),
low = "white", high = "red") +
scale_x_continuous(expand = c(0,0)) +
scale_y_continuous(expand = c(0,0)) +
ggtitle("Figure X. Margin of error\nas a function of sample size and proportion.") +
theme(plot.background = element_rect(fill = "white"),
strip.background = element_rect(fill = "white"),
text = element_text(color = "black", family = "mono"),
axis.text.x = element_text(color = "black"),
axis.text.y = element_text(color = "black"),
plot.title  = element_text(hjust = 0))


Formula for SE from here.

• Many thanks for this nice piece of advice. Could you kindly tell me more about that "context" part too? [possibly in your main post to make it even richer]? – Vic Dec 21 '13 at 19:11
• Also easy online tool for same function: at OpenEpi.com. – James Stanley Dec 22 '13 at 21:47
• To add my two cents worth on "context": if you want to estimate the proportion of people on a street who might buy a certain product being sold door-to-door, you might be happy to have a margin of error of +/- 10%; if you're wanting to estimate complication rates for a particular surgical procedure, then you might need a smaller margin of error. – James Stanley Dec 22 '13 at 21:48