Fig. 1 in words
Power
- Power of a two-sided t-test, α = 0.05, from the noncentral t (it matches statsmodels). The simulation lands on the curve: 0.794 at n = 64, 0.335 at n = 20.
- power from 0.0 to 1.0 against sample size n per group (log scale) from 5 to 1 000
- three curves: d = 0.8 (green) · d = 0.5 (blue) · d = 0.2 (purple)
- a dashed line at power 0.8, crossed at 26 · 64 · 393
- ① a red dashed line near the bottom
- ② the dashed line at 0.8
- ③ the blue curve crossing 0.8 at 64
- ④ an open red circle on the blue curve at n = 20
Entry 14 / 90
- Observer M. Tahri
- Seed 14
- Experiments 3 × 10 000
01 The Logic of a Test
- H₀: no effect. H₁: an effect of a stated size
- p: how surprising data this extreme would be if H₀ were true
Fisher (1925) called p = 0.05, "1 in 20", a convenient limit for judging significance.
02 Two Errors
- Reject H₀ · H₀ true: Type I · α · H₁ true: Power · 1 − β
- Keep H₀ · H₀ true: Correct · H₁ true: Type II · β
Neyman & Pearson (1933): fix α first, then pick the test with the most power.
03 What Sets Power
- Effect size d, sample size n, α and noise
- n grows like 1/d²: from d = 0.5 to 0.2, 64 becomes 393
Cohen (1992): 26, 64 and 393 per group for d = 0.8, 0.5 and 0.2.
04 Reading p Right
- p is not the chance that H₀ is true
- Not significant is not "no effect"
- Significant is not large or important
ASA statement (2016), principles 2 and 5.
05 Try It Yourself
sprint14_hypothesis_testing_power_sample_size.py
import numpy as np
from scipy.stats import ttest_ind
rng = np.random.default_rng(14)
def run(n, d, k=10_000):
a = rng.normal(0, 1, (k, n))
b = rng.normal(d, 1, (k, n))
p = ttest_ind(b, a, axis=1)[1]
hit = p < .05
g = b.mean(1) - a.mean(1)
return hit.mean(), g[hit].mean()
print(run(64, 0)[0]) # false alarms
for n in (64, 20):
print(n, *np.round(run(n, .5), 3))
Output, as printed on the image
0.0498
64 0.794 0.562
20 0.335 0.831
Run it. sprint14_hypothesis_testing_power_sample_size.py · versions, data and steps
06 General Notes
- Fix n and α before the data
- Power for the smallest effect that matters
- Report the effect and its interval
Low power plus a hit means an inflated effect (Gelman & Carlin, 2014).
07 Mini Project
- Rerun the code at n = 10, 40, 100
- Plot my own power curve for d = 0.5
- Find n for 90% power, then simulate it
- Log the effect the hits report at each n
