Week 08 · Hypothesis tests, p-values, and power
Measure false positives and missed effects as different frequencies.
← Week 7 · Subject contents · Week 9 →
Measure false positives and missed effects as different frequencies.
Work through the problem
Suppose per-user changes have a normal distribution with known σ = 2. Under the null of mean zero, Z = X̄/(2/√n) is standard normal. For an observed Z = 2, the two-sided p-value is P(|Z₀| ≥ 2) ≈ 0.0455, calculated under the null.
At n = 25 the test rejects when the absolute sample mean exceeds 1.96 × 0.4 = 0.784. If the true mean is 0.8, the statistic is shifted by 2. Some experiments still fall below the threshold. Power is the frequency of rejection at that specified effect.
Rejection depends on the true effect.
Run the Python lab
from math import erfc, sqrt
import numpy as np
rng = np.random.default_rng(42)
print("p-value:", round(erfc(2/sqrt(2)), 4))
rates = []
for effect in [0, .8]:
z = rng.normal(effect, .4, 20000) / .4
rates.append(np.mean(abs(z) >= 1.96))
print(effect, round(rates[-1], 3))
assert .04 < rates[0] < .06 and .49 < rates[1] < .55
Output from the lab
p-value: 0.0455
0 0.051
0.8 0.519
Practice
- What does failing to reject tell you about a small effect?
Check your reasoning
- The data did not meet the rejection rule. A small effect may still be present, especially with low power.