GARETH GRANTTECHNOLOGY · DATA · INNOVATION
Explore

17 / Inference

Sample size, precision and statistical power

Sample size follows the decision and the uncertainty it must resolve. Planning an estimate to a margin of error is different from powering a test to detect a specified effect.

IntermediateLive exploration + Python

The business question

How much useful data should we plan before an experiment or survey?

  • Budget a trial around a minimum business-relevant improvement.
  • Choose a survey size for a stated proportion margin of error.
  • Identify studies too small, too clustered or too short to support the intended decision.

How the method works

For estimation, start with the precision required. A basic independent-survey calculation uses a target margin e, a confidence critical value z and an assumed proportion p. When p is unknown, 0.5 gives the largest p(1−p) and a conservative starting size under that formula. This calculation addresses sampling uncertainty, not coverage or response bias.

For a hypothesis test, specify the smallest effect Δ that would change the business decision, the outcome standard deviation σ, the significance level α and target power 1−β. Power is the probability of rejecting the null under the specified alternative model. For two equally sized independent groups with common known variance, a normal approximation gives a simple planning formula. Unknown variance, unequal groups and different outcomes require appropriate calculations.

The resulting number refers to usable independent observations, not invitations sent, page views or repeated measurements from the same person. Inflate for realistic incomplete observations, use a design adjustment for clustering, and allow enough time for the outcome to appear. Planning choices should be fixed before collecting results; observing a non-significant result and then reporting post-hoc power does not resolve uncertainty about the effect.

The calculation

Two-group normal approximation: n per group ≈ 2(z_(1−α/2)+z_(power))²σ²/Δ²; proportion estimation: n ≈ z²p(1−p)/e²
Read the symbols
SymbolMeaning
ΔSmallest difference in means worth detecting, in original outcome units.
σAssumed common outcome standard deviation, ideally informed by relevant prior data.
α, powerFalse-positive rate under the null and target detection probability at the specified alternative.
eDesired absolute half-width for a proportion estimate; 0.05 means five percentage points.

A worked business example

ILLUSTRATIVE SCENARIO

Illustrative service company plans a randomised two-group trial. A five-minute mean improvement matters economically, and prior comparable work suggests a ten-minute standard deviation. A separate survey needs roughly five-percentage-point precision.

Inputs

  • Trial: Δ = 5 minutes, σ = 10 minutes, two-sided α = 0.05, power = 0.80, equal groups.
  • Normal-approximation planning calculation with common variance.
  • Survey: 95% confidence, p = 0.5 and e = 0.05; simple independent sampling with no finite-population correction.

Work through the numbers

  1. Use z_0.975 = 1.959964 and z_0.80 = 0.841621.
  2. Trial n per group ≈ 2 × (1.959964 + 0.841621)² × 10²/5² = 62.791; round upward to 63 usable observations per group.
  3. If only 80% of invited trial participants provide a usable outcome, 63/0.80 = 78.75 suggests inviting at least 79 per group, without guaranteeing completion.
  4. Survey n ≈ 1.959964² × 0.5 × 0.5/0.05² = 384.146; round upward to 385 usable responses.
Approximate trial plan: 63 usable observations per group. Separate survey precision plan: 385 responses.

The two sample sizes answer different questions. The trial figure is a starting approximation; a final t-based, cluster-adjusted or binary-outcome design may need a different size.

Explore the decision

Plan a two-group mean comparison. The live explorer has its own example inputs; it is separate from the worked calculation above.

Enable JavaScript to use this calculator. The worked example and executable Python remain available.

Apply it at work

  1. State the estimand, decision threshold and smallest useful effect before choosing a sample size.
  2. Choose the appropriate design and obtain realistic variability, response and clustering assumptions.
  3. Calculate size under several defensible assumptions and round usable sample requirements upward.
  4. Translate the requirement into recruitment, operating time and follow-up, then document the analysis plan before starting.

Check these assumptions

  • The worked trial approximation assumes equal independent groups and a common known or planning standard deviation.
  • The alternative effect Δ is specified in advance and measured in the same units as σ.
  • The survey formula assumes simple independent sampling; large sampling fractions and complex designs need adjustment.
  • A response-rate inflation is an expectation, not a promise of an achieved usable sample.

Common mistakes and how to avoid them

  • A universal rule such as thirty observations ignores effect size, variability and the design.
  • Halving the desired detectable effect roughly quadruples the required size under the simple formula.
  • Repeatedly checking a conventional fixed-sample test and stopping at significance changes its error behaviour.

How this can help the business

  • A pilot budget can be compared with the value of resolving a decision-relevant uncertainty.
  • An infeasible sample requirement may suggest a larger effect target, a better measurement, a more efficient design or an explicitly exploratory pilot.
A decision rule to adapt

Choose a feasible design that can resolve the minimum useful effect or estimation precision; if it cannot, change the plan before treating the study as decisive.

When to use another approach

Use exact or simulation-based power, a paired design where justified, or an adaptive design with an appropriate pre-specified analysis.

Reproduce the worked example in Python

The code is self-contained for this example. Dependencies and run instructions are included with the downloadable notebook.

Show executable code and recorded output
from math import ceil
from scipy.stats import norm
alpha, power = 0.05, 0.80
sd, useful_difference = 10, 5
z_alpha = norm.ppf(1-alpha/2)
z_power = norm.ppf(power)
per_group = ceil(2*(z_alpha+z_power)**2*sd**2/useful_difference**2)
survey_size = ceil(z_alpha**2*0.5*0.5/0.05**2)
print(f'Approximate usable trial observations per group: {per_group}')
print(f'Invitations per group at 80% completion: {ceil(per_group/0.80)}')
print(f'Survey responses for +/-5 percentage points: {survey_size}')

Recorded output

Approximate usable trial observations per group: 63
Invitations per group at 80% completion: 79
Survey responses for +/-5 percentage points: 385
Download all worked examples

Sources and further reading

Concepts are linked to primary teaching or technical sources. The business examples are illustrative applications, not reported client results.