Intermediate level · Module 3: Statistical Inference · Lesson 2 of 3
Hypothesis Testing
Use t-tests and chi-square tests to judge whether differences are larger than chance would explain.
In this lesson you will
- State null and alternative hypotheses
- Choose and run t-tests and chi-square tests with SciPy
Key concepts
null hypothesisp-valuet-testchi-square test
The lesson
A hypothesis test asks how surprising the data would be if there were no real difference (the null hypothesis). The p-value is that probability; a small p-value suggests the difference is unlikely to be chance alone.
Compare two group means with a t-test (scipy.stats.ttest_ind, using equal_var=False when spreads differ). Test association between two categorical variables with a chi-square test on a cross-tabulation.
Check assumptions: independent observations, reasonable sample sizes, expected cell counts above about five for chi-square. Clustered survey data needs methods that account for the design.
Step by step
- Write hypotheses for the girls/boys attendance question.
- Run a t-test and report the result.
- Cross-tabulate attendance level by school type and run a chi-square test.
- Check the assumptions.
Practice activity
Run the two tests from the practical activity and interpret them.
Expected result: Correct tests, assumption checks and interpretations.
Check your understanding
-
What does a p-value measure?
Show answer
How likely data at least this extreme would be if the null hypothesis were true.
-
Which test checks association between two categorical variables?
Show answer
The chi-square test.
Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.