Math for Causal Inference

Day 10. Hypothesis Testing, p-Values & Power

Deciding whether an effect is distinguishable from zero, and designing studies that can tell.

Video coming soon
Learning outcomes
  • ●Set up a test, compute a z-statistic and p-value, and state the decision correctly.
  • ●Prove that p-values are uniform under the null.
  • ●Derive the power formula, the required sample size and the minimum detectable effect.
  • ●Explain multiple testing, statistical versus economic significance, and the winner's curse.
2-HOUR SESSION PLAN
Theory 25′Warm-up (1–5) 20′Proofs (6–10) 35′Applied (11–15) 25′Python & Lab 15′
Colab notebook (.ipynb) Jump to the simulator

Theory

The logic of a test

  1. State a null hypothesis H0:τ=0H_0: \tau = 0 and an alternative H1:τ≠0H_1: \tau \ne 0.
  2. Compute a test statistic whose distribution under H0H_0 is known: z=τ^/SE⁡≈N(0,1)z = \hat\tau/\operatorname{SE} \approx N(0, 1).
  3. The p-value is the probability, if H0H_0 were true, of a statistic at least as extreme as the one observed: p=2(1−Φ(∣z∣))p = 2\big(1 - \Phi(|z|)\big).
  4. Reject H0H_0 at level α\alpha when p<αp < \alpha, equivalently ∣z∣>z1−α/2|z| > z_{1-\alpha/2}.

Two kinds of error

H0H_0 trueH0H_0 false
RejectType I error (prob. α\alpha)Correct (prob. = power)
Do not rejectCorrectType II error (prob. β\beta)

Power, sample size and the MDE

If the true effect is τ\tau, then z≈N(τ/SE⁡,1)z \approx N(\tau/\operatorname{SE}, 1) and

Power≈Φ(∣τ∣SE⁡−z1−α/2).\text{Power} \approx \Phi\Big(\frac{|\tau|}{\operatorname{SE}} - z_{1-\alpha/2}\Big).

For two arms of size nn with outcome SD σ\sigma, SE⁡=σ2/n\operatorname{SE} = \sigma\sqrt{2/n}. Solving for power 1−β1 - \beta:

n=2σ2 (z1−α/2+z1−β)2τ2,MDE=(z1−α/2+z1−β) SE⁡.n = \frac{2\sigma^2\,(z_{1-\alpha/2} + z_{1-\beta})^2}{\tau^2}, \qquad \text{MDE} = (z_{1-\alpha/2} + z_{1-\beta})\,\operatorname{SE}.

With α=0.05\alpha = 0.05 and 80% power, z0.975+z0.8=1.96+0.84=2.80z_{0.975} + z_{0.8} = 1.96 + 0.84 = 2.80: the MDE is 2.8 standard errors.

Pitfalls

  • Multiple testing: with many tests, some will be "significant" by chance.
  • Statistical ≠ economic significance: huge samples make tiny effects significant.
  • Winner's curse: in underpowered studies, estimates that clear the significance bar are exaggerated.

Part 1 · Warm-up

Exercise 1 · Hypotheses

A job-training programme's effect on earnings is τ\tau. Write the null and two-sided alternative for "the programme has an effect".

Show solution

H0:τ=0H_0: \tau = 0 versus H1:τ≠0H_1: \tau \ne 0.

Exercise 2 · A z-statistic

The estimated effect is 3.2 (thousand dollars) with SE 1.25. Compute zz.

Show solution

z=3.2/1.25=2.56z = 3.2/1.25 = 2.56.

Exercise 3 · Decision and p-value

Is the effect significant at 5%? Compute the p-value.

Show solution

∣z∣=2.56>1.96|z| = 2.56 > 1.96, so reject H0H_0. p=2(1−Φ(2.56))≈0.0105p = 2(1 - \Phi(2.56)) \approx 0.0105.

Exercise 4 · What a p-value is not

A report says "p = 0.01, so there is a 1% chance the programme has no effect." Correct it.

Show solution

The p-value is computed assuming H0H_0 is true: if the programme had no effect, results at least this extreme would occur about 1% of the time. It is not P(H0∣data)P(H_0 \mid \text{data}); that requires a prior (Day 13).

Exercise 5 · Trading off errors

What happens to Type I and Type II error rates if you lower α\alpha from 0.05 to 0.01 with the same data?

Show solution

Type I falls to 1%, but the critical value rises from 1.96 to 2.576, so real effects are rejected less often: Type II error rises and power falls. Only more information (larger nn, less noise) lowers both.

Part 2 · Proofs

Exercise 6 · p-values are uniform under the null

Let the statistic ZZ have continuous CDF FF under H0H_0, and define the one-sided p-value p=1−F(Z)p = 1 - F(Z). Show p∼Uniform(0,1)p \sim \text{Uniform}(0, 1) under H0H_0.

Show solution

For u∈(0,1)u \in (0, 1): P(p≤u)=P(F(Z)≥1−u)=P(Z≥F−1(1−u))=1−F(F−1(1−u))=uP(p \le u) = P(F(Z) \ge 1 - u) = P(Z \ge F^{-1}(1 - u)) = 1 - F(F^{-1}(1 - u)) = u. So under H0H_0 every p-value is equally likely, and P(p<0.05)=0.05P(p < 0.05) = 0.05 by construction.

Exercise 7 · The power formula

Derive Power=Φ(τ/SE⁡−z1−α/2)+Φ(−τ/SE⁡−z1−α/2)\text{Power} = \Phi(\tau/\operatorname{SE} - z_{1-\alpha/2}) + \Phi(-\tau/\operatorname{SE} - z_{1-\alpha/2}).

Show solution

Step 1. Under the alternative, z=τ^/SE⁡∼N(δ,1)z = \hat\tau/\operatorname{SE} \sim N(\delta, 1) with δ=τ/SE⁡\delta = \tau/\operatorname{SE}.

Step 2. With c=z1−α/2c = z_{1-\alpha/2}:

P(z>c)=1−Φ(c−δ)=Φ(δ−c),P(z<−c)=Φ(−c−δ).P(z > c) = 1 - \Phi(c - \delta) = \Phi(\delta - c), \qquad P(z < -c) = \Phi(-c - \delta).

Step 3. Add them.

Step 4. For δ>0\delta > 0 the second term is tiny, giving the approximation in the theory block.

Exercise 8 · Sample size

Derive n=2σ2(z1−α/2+z1−β)2/τ2n = 2\sigma^2(z_{1-\alpha/2} + z_{1-\beta})^2/\tau^2 per arm, and apply it with σ=10\sigma = 10, τ=2\tau = 2, α=0.05\alpha = 0.05, power 0.8.

Show solution

Derivation

Step 1. Approximate power: Φ(τ/SE⁡−z1−α/2)=1−β\Phi(\tau/\operatorname{SE} - z_{1-\alpha/2}) = 1 - \beta.

Step 2. Apply Φ−1\Phi^{-1}: τ/SE⁡=z1−α/2+z1−β\tau/\operatorname{SE} = z_{1-\alpha/2} + z_{1-\beta}.

Step 3. Substitute SE⁡=σ2/n\operatorname{SE} = \sigma\sqrt{2/n}: τn/(σ2)=z1−α/2+z1−β\tau\sqrt n/(\sigma\sqrt2) = z_{1-\alpha/2} + z_{1-\beta}.

Step 4. Square and solve: n=2σ2(z1−α/2+z1−β)2/τ2n = 2\sigma^2(z_{1-\alpha/2} + z_{1-\beta})^2/\tau^2.

Application

Step 5. z0.975=1.96z_{0.975} = 1.96, z0.80=0.8416z_{0.80} = 0.8416, so (1.96+0.8416)2=2.80162≈7.849(1.96 + 0.8416)^2 = 2.8016^2 \approx 7.849.

Step 6. n=2(100)(7.849)/4≈392.4n = 2(100)(7.849)/4 \approx 392.4; round up.

Answer: 393 per arm.

Exercise 9 · Unequal allocation

With a fixed total NN and a share pp treated, Var⁡(τ^)=σ2/(Np(1−p))\operatorname{Var}(\hat\tau) = \sigma^2/(Np(1 - p)). Show p=0.5p = 0.5 is optimal and find the cost of a 70/30 split.

Show solution

Step 1. Var⁡(τ^)=σ2/(Np(1−p))\operatorname{Var}(\hat\tau) = \sigma^2/(Np(1 - p)) is smallest when p(1−p)p(1 - p) is largest, which happens at p=0.5p = 0.5 (Day 3, Exercise 12).

Step 2. At a 70/30 split, p(1−p)=0.21p(1 - p) = 0.21, versus 0.25 at 50/50.

Step 3. Variance ratio: 0.25/0.21≈1.190.25/0.21 \approx 1.19.

Answer: 50/50 is optimal; a 70/30 split needs about 19% more people for the same precision (still worth it if treatment is expensive, Day 26).

Exercise 10 · The winner's curse

The true effect is τ=1\tau = 1 and SE⁡=1\operatorname{SE} = 1. Compute the power, and the expected estimate given that it is significantly positive. Hint: if X∼N(μ,1)X \sim N(\mu, 1), then E[X∣X>c]=μ+ϕ(c−μ)/(1−Φ(c−μ))E[X \mid X > c] = \mu + \phi(c - \mu)/(1 - \Phi(c - \mu)).

Show solution

Step 1. Power: τ/SE⁡=1\tau/\operatorname{SE} = 1, so power ≈Φ(1−1.96)=Φ(−0.96)≈0.17\approx \Phi(1 - 1.96) = \Phi(-0.96) \approx 0.17.

Step 2. Given a significant positive result, use the truncated-normal mean with μ=1\mu = 1, c=1.96c = 1.96, c−μ=0.96c - \mu = 0.96:

E[τ^∣τ^>1.96]=1+ϕ(0.96)1−Φ(0.96).E[\hat\tau \mid \hat\tau > 1.96] = 1 + \frac{\phi(0.96)}{1 - \Phi(0.96)}.

Step 3. ϕ(0.96)=0.3989 e−0.962/2≈0.2516\phi(0.96) = 0.3989\,e^{-0.96^2/2} \approx 0.2516 and 1−Φ(0.96)≈0.16851 - \Phi(0.96) \approx 0.1685; ratio ≈ 1.493.

Step 4. E[τ^∣significant]≈2.49E[\hat\tau \mid \text{significant}] \approx 2.49.

Answer: power is only 17%, and the significant estimates average 2.5 times the true effect. Small published studies often overstate effects for this reason.

Part 3 · Applied

Exercise 11 · One-sided or two-sided? A cash-transfer test

A conditional cash transfer's effect on school enrolment gives z=1.80z = 1.80. The team had planned a two-sided test. Compute the one-sided and two-sided p-values. Which should be reported?

Show solution

Step 1. One-sided: P(Z>1.80)=1−Φ(1.80)≈0.036P(Z > 1.80) = 1 - \Phi(1.80) \approx 0.036.

Step 2. Two-sided: 2×0.036=0.0722 \times 0.036 = 0.072.

Answer: report the pre-planned two-sided p=0.072p = 0.072. Switching to one-sided after seeing the sign doubles the false-positive rate; one-sided tests are fine only if pre-registered for a substantive reason (e.g. the transfer cannot plausibly reduce enrolment).

Exercise 12 · An underpowered nutrition trial

A nutrition supplement trial can estimate the effect on child height with SE 1.5 cm. If the true effect is 3 cm, what is the trial's power at the 5% level?

Show solution

Step 1. Standardised effect: τ/SE⁡=3/1.5=2\tau/\operatorname{SE} = 3/1.5 = 2.

Step 2. Power ≈Φ(2−1.96)=Φ(0.04)≈0.52\approx \Phi(2 - 1.96) = \Phi(0.04) \approx 0.52.

Answer: about 52%: a coin flip. A null result from this trial would say little about whether the supplement works.

Exercise 13 · Minimum detectable effect

With 500 per arm and σ=20\sigma = 20, what is the MDE at 5% significance and 80% power?

Show solution

Step 1. SE⁡=σ2/n=202/500=20×0.0632≈1.265\operatorname{SE} = \sigma\sqrt{2/n} = 20\sqrt{2/500} = 20 \times 0.0632 \approx 1.265.

Step 2. MDE multiplier at 5% and 80% power: 1.96+0.84=2.801.96 + 0.84 = 2.80.

Step 3. MDE=2.80×1.265≈3.54\text{MDE} = 2.80 \times 1.265 \approx 3.54.

Answer: the study can reliably detect effects of about 3.5 units or more.

Exercise 14 · Twenty outcomes

A study tests 20 independent outcomes at 5%, and the programme truly affects none. What is the chance of at least one "significant" result? What threshold does Bonferroni use?

Show solution

Step 1. Each test has a 0.95 chance of not giving a false positive; independent, so all 20 avoid one with probability 0.9520≈0.3580.95^{20} \approx 0.358.

Step 2. At least one false positive: 1−0.358≈0.641 - 0.358 \approx 0.64.

Step 3. Bonferroni divides the level by the number of tests: 0.05/20=0.00250.05/20 = 0.0025. By Boole's inequality (Day 1), the chance of any false positive is then at most 20×0.0025=0.0520 \times 0.0025 = 0.05.

Answer: a 64% chance of at least one spurious "effect"; Bonferroni tests each outcome at 0.0025.

Exercise 15 · Statistical versus economic significance

On 5 million tax records, a policy raises earnings by $1.50 a year with p<0.0001p < 0.0001. Interpret.

Show solution

Step 1. z=τ^/SE⁡z = \hat\tau/\operatorname{SE} with SE⁡=σ/n\operatorname{SE} = \sigma/\sqrt n.

Step 2. With n=5,000,000n = 5{,}000{,}000, n≈2,236\sqrt n \approx 2{,}236, so the SE is tiny and even $1.50 gives a huge zz.

Answer: the effect is precisely estimated (statistically significant) but negligible in size (economically insignificant). Report the effect and its CI, not just the p-value.

Verify in Python

import numpy as np
from scipy import stats

z = 3.2 / 1.25
print(f"z = {z:.2f}, p = {2 * stats.norm.sf(z):.4f}")

za, zb = stats.norm.ppf(0.975), stats.norm.ppf(0.80)
print("n per arm:", np.ceil(2 * 10**2 * (za + zb)**2 / 2**2))
print("MDE:", round((za + zb) * 20 * np.sqrt(2 / 500), 2))
print("P(>=1 false positive in 20):", round(1 - 0.95**20, 3))

# Winner's curse by simulation
rng = np.random.default_rng(10)
est = rng.normal(1, 1, 1_000_000)
sig = est > za
print(f"power {sig.mean():.3f}; mean significant estimate {est[sig].mean():.2f} (truth 1)")

# p-values are uniform under H0
p = 2 * stats.norm.sf(np.abs(rng.normal(0, 1, 100_000)))
print("share p < 0.05 under H0:", round((p < 0.05).mean(), 3))

Key takeaways

  • A p-value measures how surprising the data would be if the null were true.
  • Power depends on effect size relative to the SE; the MDE at 80% power is about 2.8 SEs.
  • Watch for multiple testing, tiny-but-significant effects and exaggerated significant estimates.

Simulation Lab: Statistical Power Visualiser

Open full screen →

The null and alternative sampling distributions, the rejection region, α, β and power.

00.10.20.30.4-4-20246estimated effectdensitycritical value 1.96
H₀: τ = 0H₁: true effect τ
Power
51.6%
β = 48.4%
Standard error
1.000
σ√(2/n)
MDE at 80% power
2.80
2.80 × SE
n per arm for 80%
393

Blue: where the estimate lands if there is no effect. Orange: where it lands if the effect is τ. Shaded orange = power; shaded blue tails = α; the hatched part of the orange curve inside the critical values = β.

Day 9Day 11