Sample size calculation

Flip the CI formula to choose how large $n$ must be for a desired margin of error $e$.

Before collecting data, decide how tight you want the estimate. Smaller $e$ demands much larger $n$ (it scales like $1/e^2$).

Mean

At 95% confidence: $$n = \dfrac{1.96^2 s_x^2}{e^2}$$ (guess $s_x$ from a pilot study).

Proportion

At 95% confidence: $$n = \dfrac{1.96^2 p(1-p)}{e^2}$$ (use $p=0.5$ as a conservative worst case).

Image recognition accuracy
  • Want ±5% around ~95% accuracy ⇒ $n \approx 73$.
  • Want ±1% around ~90% accuracy ⇒ $n \approx 3457$.

With $n=73$ you might get a CI like 85–98% — still overlapping 90%. With thousands of images the CI shrinks and you can actually tell systems apart.

Key takeaways

  • Halving the error bar needs roughly $4\times$ the sample size.
  • You must guess variance or $p$ up front.
  • Plan $n$ before you collect when stakes are high.