Chapter 3 covered hypothesis testing; the practical question is which test to run. The answer depends on your data types and what you're comparing. This chapter is a decision map for the everyday tests, so you can pick confidently rather than guessing.
The decision framework
Ask two questions: what type is your outcome, and what are you comparing?
| Question | Test |
|---|---|
| Is one numeric mean different from a value? | One-sample t-test |
| Do two groups differ on a numeric mean? | Two-sample t-test |
| Before vs after on the same subjects? | Paired t-test |
| Do 3+ groups differ on a mean? | ANOVA |
| Are two categorical variables related? | Chi-squared |
| Do two numeric variables move together? | Correlation test |
t-tests
The t-test family compares means. It returns a p-value; below 0.05 conventionally means "unlikely to be chance":
from scipy import statsstats.ttest_1samp(scores, 50) # vs a benchmark of 50stats.ttest_ind(group_a, group_b) # two independent groupsstats.ttest_rel(before, after) # paired (same subjects)
ANOVA
For three or more groups, don't run many t-tests (it inflates false positives). ANOVA tests whether any group mean differs, in one test:
stats.f_oneway(group_a, group_b, group_c) # one-way ANOVA# A significant result says "at least one differs" — follow up to find which.
Chi-squared
For relationships between categorical variables (is placement rate independent of programme?), use the chi-squared test:
stats.chi2_contingency(contingency_table) # a table of counts
Practice
For each scenario, name the test: comparing average package across three programmes; before/after scores for the same students; whether placement (yes/no) depends on programme. Then run the appropriate scipy.stats test on sample data and interpret the p-value.
Key takeaways
- 01Pick a test by outcome type and what you're comparing.
- 02t-tests compare means: one-sample (vs a value), two-sample (two groups), paired (before/after).
- 03ANOVA compares 3+ group means in one test — don't run many t-tests instead.
- 04Chi-squared tests association between categorical variables.
- 05Match test to data and check assumptions (normality, independence, sample size).
