SimuVeda/ Mathematics

Mathematics · Simulator 052

Hypothesis Testing

Run the same experiment thousands of times. When there is no real effect, see how often you still get “significant” results (false positives). When there is a real effect, see how often you detect it (power), and how both depend on sample size and the significance threshold.

CollegeCollege statistics

Experiments 0 of 0 Challenge not tried

How the model works

Each simulated experiment compares a treatment group with a control group (n per group, values with standard deviation 1). A two-sample z-test gives a p-value: the probability of a difference at least this large if there were no real effect (the null hypothesis).

  • Declaring “significant” when p < α means that, under the null, a fraction α of experiments are false positives (Type I errors).
  • Power is the chance of detecting a real effect of size d (in SD units). Approximately power ≈ Φ(d√(n/2) − z₁₋α/₂). It grows with effect size and sample size.
  • Under the null, p-values are uniformly distributed between 0 and 1. With a real effect, they pile up near 0.

The “peek and stop” option checks after every 10 participants and stops as soon as p < α. That inflates false positives well above α, a common real-world error.

Normal data with known variance (z-test) for clarity. Real studies often use t-tests and face many other issues.

Guided experiments

  1. No effect, α = 0.05. Run 2000 experiments with d = 0. Prediction: about 5% come out “significant”, all false positives. The p-value histogram is flat.
  2. Underpowered study. d = 0.3, n = 20 per group. Prediction: power is only about 16%; most real effects are missed.
  3. Peeking. d = 0 with “peek and stop”. Prediction: false positives climb to around 20–25%, far above the nominal 5%.

Challenge

How many participants per group do you need for 80% power to detect d = 0.5 at α = 0.05 (two-sided)?

Reveal the explanation

Need d√(n/2) ≈ 1.96 + 0.84 = 2.80, so √(n/2) = 5.6 and n ≈ 63 per group. Set d = 0.5 and n = 63 and check that the measured power is near 80%.

References

  • OpenStax, Introductory Statistics, ch. 9 “Hypothesis Testing with One Sample”.
  • Simmons, Nelson & Simonsohn (2011), “False-positive psychology”, Psychological Science 22: 1359–1366.

Related simulators

Worked example

One experiment: two groups of 50, outcome measured in standard-deviation units. The treated group's mean is 0.5 higher.

Test statistic: the standard error of the difference is √(2/50) = 0.2, so z = 0.5 / 0.2 = 2.5.

p-value: 2 × (1 − Φ(2.5)) ≈ 2 × 0.0062 ≈ 0.012. That is below α = 0.05, so the result is called significant.

Power: if the true effect is d = 0.5, the chance of a significant result with 50 per group is Φ(0.5 × √25 − 1.96) = Φ(0.54) ≈ 71%. About 3 in 10 such studies would miss a real effect.

Many tests: run 20 independent tests where nothing is going on, and the chance of at least one false positive is 1 − 0.95²⁰ ≈ 64%. Set d = 0.5 and n = 50 and compare the measured share with 71%.

Common questions

What does a p-value mean?

The probability of getting a result at least as extreme as the one observed if there were really no effect. It is not the probability that the null hypothesis is true.

What are Type I and Type II errors?

A Type I error is a false positive: declaring an effect that is not there, which happens with probability α. A Type II error is a false negative: missing a real effect, which happens with probability 1 − power.

Why does peeking at the data raise false positives?

Every look is another chance for random noise to cross the threshold. Stopping at the first significant look turns a 5% test into a much higher one unless the threshold is adjusted for the number of looks.

Keyboard shortcuts

Space
Play or pause
S
Step
R
Reset
F
Full screen
?
Show this list