Summary and Practical Guide to Hypothesis Testing › scipy.stats Quick Reference

Michael BrenndoerferJanuary 10, 20261 min read
Machine Learning from ScratchAll chapters
Part 2 of 9Hypothesis Testing
Chapter 22Summary and Practical Guide to Hypothesis Testing › scipy.stats Quick Reference
Reading section 9 of 12 · scipy.stats Quick Reference · 1 minSection 9 of 12 · 1 min

Book contents

Section 9 of 12 · 1 min read

Summary and Practical Guide to Hypothesis Testing › scipy.stats Quick ReferenceOne section · Sections in this chapter9 / 12 ↓
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

Testing Functions

In[2]:
Code
from scipy import stats

# One-sample tests
stats.ttest_1samp(sample, popmean)  # One-sample t-test
stats.shapiro(sample)  # Normality test

# Two-sample tests
stats.ttest_ind(a, b, equal_var=True)  # Pooled t-test
stats.ttest_ind(a, b, equal_var=False)  # Welch's t-test
stats.ttest_rel(a, b)  # Paired t-test
stats.levene(a, b)  # Equal variance test

# Multiple groups
stats.f_oneway(g1, g2, g3, ...)  # One-way ANOVA
stats.tukey_hsd(g1, g2, g3, ...)  # Tukey post-hoc
stats.dunnett(t1, t2, control=ctrl)  # Dunnett post-hoc

# Multiple comparison corrections
stats.false_discovery_control(pvals, method="bh")  # BH correction
stats.false_discovery_control(pvals, method="by")  # BY correction

Distribution Functions

In[4]:
Code
# For manual calculations
stats.norm.ppf(0.975)  # Z critical value (two-tailed, α=0.05)
stats.t.ppf(0.975, df)  # t critical value
stats.f.ppf(0.95, df1, df2)  # F critical value

# P-values from test statistics
stats.norm.sf(z) * 2  # Two-tailed p from z
stats.t.sf(t, df) * 2  # Two-tailed p from t
stats.f.sf(f, df1, df2)  # Upper-tail p from F