Put uncertainty to workLesson 20 of 30 · 7 min

Choose the sample size before the result

Explain how sample size, variation and effect size affect detection probability.

A null hypothesis is a statistical reference claim, here that the population mean difference is zero. A hypothesis test compares an observed statistic, such as a sample mean, with what a specified model predicts under that claim. Its decision rule can reject the null when the statistic is sufficiently extreme.

Power is the chance a specified test detects an effect of a particular size under a given sampling model. The test here detects differences on either side of zero. It calls a result a detection when its p-value, the probability of results at least this extreme under the no-effect model and test assumptions, is below 0.05.

This simulation asks how often that test detects a 3 ms shift with independent normal differences of standard deviation 10 ms. Rejecting at p<0.05 is a prespecified simulation rule, not a truth threshold. Each row repeats whole experiments at one fixed sample size.

Choose the effect that matters and a precision or power goal before collecting real data. A noisy pilot’s estimated effect can be optimistic. Sensitivity analysis over plausible effects and variation gives a more honest plan than one exact-looking count.

More evidence, same effect
025507510000.250.50.751Detection fractionIndependent sample size
025507510000.250.50.751Detection fractionIndependent sample size
Actual seeded reference output: 600 normal experiments at each tested count, a 3 ms effect, SD 10 ms, and a two-sided t test with p < 0.05. Lines join the three tested counts; other counts were not simulated here.

Will a larger sample make a tiny effect more practically useful?

Write a prediction (optional)

Run the prepared example

This page puts the example in the Python editor. Select Run Python with the code unchanged.

Seeded simulation

Editor tools
About Python ↗

Ctrl+Enter or ⌘+Enter runs the code.

What to compare

Compare Simulated detection fraction across the three sample sizes, labelled n. The generator keeps the effect at 3 ms and standard deviation at 10 ms. Does a larger sample change the effect itself or the chance of detecting it?

Published example output

The site ran the original code to produce this reference. Build environment ↗

n= 10 simulated detection fraction=0.160
n= 30 simulated detection fraction=0.323
n=100 simulated detection fraction=0.860

More independent observations make a mean easier to distinguish from zero under this model. When the effect is zero, detections are false positives.

Change and run again

In the Python editor, replace effect_ms, sd_ms = 3, 10 with effect_ms, sd_ms = 0, 10 and select Run Python. Repeat with 1, 10 and 6, 10. At n=100, compare Simulated detection fraction for the three effects. What does the fraction count when the true effect is zero? Return to the Python editor

What this example supports. Power is simulated under one normal independent-difference model. It does not establish an appropriate sample size for an unmodelled real experiment.

Try a fresh case

A study fails to reject zero with a small sample. Which conclusion follows?

Choose an answer

Hints for this question
  1. Ask what range of effects is still compatible with the evidence.
  2. Separate lack of evidence from evidence for a sufficiently small effect.
Your notes