Summary and Practical Guide to Hypothesis Testing › Power Analysis Quick Reference
Michael BrenndoerferJanuary 10, 20262 min read
Machine Learning from ScratchAll chapters Part 2 of 9Hypothesis Testing
Summary and Practical Guide to Hypothesis Testing › Power Analysis Quick ReferenceOne section · Sections in this chapter5 / 12 ↓
Sections in this chapter12
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
Power analysis determines the sample size needed to detect an effect of a given size with specified probability.
The Power Pentagon
Five quantities are interconnected: knowing any four determines the fifth:
- Sample size (n): Number of observations
- Effect size (d): Magnitude of the effect
- Significance level (α): False positive rate
- Power (1-β): True positive rate
- Variability (σ): Data spread
Sample Size Formulas
One-sample t-test:
Two-sample t-test (equal groups):
Two proportions:
Sample Size Table (Two-Sample t-test, α = 0.05, Two-tailed)
| Effect Size | Power = 0.80 | Power = 0.90 | Power = 0.95 |
|---|---|---|---|
| d = 0.2 (small) | 394 per group | 527 per group | 651 per group |
| d = 0.5 (medium) | 64 per group | 86 per group | 105 per group |
| d = 0.8 (large) | 26 per group | 34 per group | 42 per group |
In[5]:
Code# Power analysis with statsmodels
from statsmodels.stats.power import TTestIndPower
analysis = TTestIndPower()
# Calculate required sample size
n = analysis.solve_power(effect_size=0.5, power=0.8, alpha=0.05)
print(f"For d=0.5, power=0.80, α=0.05: n = {n:.0f} per group")
# Calculate power for given sample size
power = analysis.solve_power(effect_size=0.5, nobs1=50, alpha=0.05)
print(f"For d=0.5, n=50/group, α=0.05: power = {power:.2f}")
# Calculate detectable effect size
mde = analysis.solve_power(nobs1=100, power=0.8, alpha=0.05)
print(f"For n=100/group, power=0.80, α=0.05: MDE = {mde:.3f}")Out[5]:
ConsoleFor d=0.5, power=0.80, α=0.05: n = 64 per group For d=0.5, n=50/group, α=0.05: power = 0.70 For n=100/group, power=0.80, α=0.05: MDE = 0.398