Chi-squared tests: goodness of fit and independence
IB Mathematics AI HLΒ· Unit 5: Statistics and probabilityΒ· 6 min read
1. Foundations of the Chi-Squared Goodness of Fit Testβ β ββββ± 15 min
Chi-squared goodness of fit test
A hypothesis test that assesses whether an observed frequency distribution matches a hypothesized theoretical distribution.
Example:
Testing if a six-sided die is fair by comparing observed roll counts to expected uniform counts
All chi-squared tests use the same core formula for the test statistic, which quantifies how far observed values are from the values expected under the null hypothesis:
A clinic claims blood type proportions are 0.45 (O), 0.40 (A), 0.11 (B), 0.04 (AB). A sample of 200 people gives observed counts: 92, 75, 24, 9. Calculate the chi-squared test statistic.
- 1
First calculate expected frequencies by multiplying total sample size by the hypothesized proportion for each category:
- 2
- 3
Calculate the term for each category:
- 4
- 5
Sum all terms to get the final test statistic:
- 6
Exam tip:
If asked to show the chi-squared calculation, always show each individual term to get full marks.
2. Degrees of Freedom and Validity Conditionsβ β β βββ± 15 min
Degrees of freedom for a goodness of fit test depends on how many parameters of the hypothesized distribution were estimated from your sample data, which is a common exam trap.
Degrees of freedom (goodness of fit)
Calculated as , where is the number of categories, and is the number of distribution parameters estimated from the sample.
Example:
For a normal distribution goodness of fit test with 8 categories, where mean and standard deviation are estimated, so
Find the correct degrees of freedom for a goodness of fit test of a uniform distribution with 6 categories, where no parameters are estimated from the sample.
- 1
Identify the values for (number of categories) and (number of estimated parameters):
- 2
- 3
Apply the degrees of freedom formula:
- 4
3. Chi-Squared Test for Independenceβ β β βββ± 20 min
The chi-squared test for independence assesses whether two categorical variables are associated (related) or independent, using data arranged in a contingency table.
Test for independence
A chi-squared test that tests the null hypothesis that two categorical variables from the same population are independent of each other.
For a contingency table with rows and columns, the expected frequency for each cell is calculated as:
Degrees of freedom for a test of independence is always calculated as:
A 3Γ2 contingency table (3 rows, 2 columns) is used to test if age group is associated with preference for a product. Find the correct degrees of freedom for the test.
- 1
Identify the number of rows and columns :
- 2
- 3
Apply the degrees of freedom formula for independence:
- 4
Check your understanding:
What is the degrees of freedom for a chi-squared test of independence in a 3Γ3 contingency table?
9
4
6
3
Reveal answer
4 βCorrect!
4. Hypotheses and Conclusion Writingβ β ββββ± 10 min
For all chi-squared tests, the null hypothesis always states there is no effect: for goodness of fit, = the observed distribution matches the theoretical distribution. For independence, = the two variables are independent. The alternative hypothesis always states there is an effect (distribution does not match / variables are associated).
To draw your conclusion: reject if critical value, or (usually 0.05). Otherwise, fail to reject .
5. Common Pitfalls
Wrong move:
Using for goodness of fit when parameters were estimated from the sample
Why:
This gives an incorrect degrees of freedom, leading to the wrong critical value and wrong conclusion
Correct move:
Always subtract the number of estimated parameters first:
Wrong move:
Using instead of for independence tests
Why:
This overestimates degrees of freedom, leading to an incorrect significance test result
Correct move:
Memorize the correct formula for all contingency table tests
Wrong move:
Leaving expected frequencies < 5 unadjusted
Why:
The chi-squared approximation is invalid for small expected frequencies, so your result will be unreliable
Correct move:
Combine adjacent categories to make all expected frequencies at least 5 before calculating the test statistic
Wrong move:
Claiming you have proven independence when you fail to reject
Why:
Failure to reject the null hypothesis only means there is insufficient evidence to reject it, not that it is proven true
Correct move:
Write 'there is insufficient evidence at the 5% significance level to conclude the variables are associated' instead of 'the variables are independent'
Wrong move:
Forgetting to check that expected frequencies sum to the grand total
Why:
A mismatched sum is a clear sign of calculation error that will cost you marks
Correct move:
Always sum your expected frequencies and confirm they equal the grand total of observed frequencies
6. Quick Reference Cheatsheet
Item | Formula / Rule |
|---|---|
Chi-squared test statistic | |
Expected frequency (independence) | |
Goodness of fit df (k estimated parameters) | |
Independence test df (rΓc table) | |
Goodness of fit | Observed distribution matches theoretical distribution |
Independence test | Two categorical variables are independent |
Validity condition | All expected frequencies |
When this came up on past exams
AI-estimated based on syllabus patterns β cross-check with official past papers for accuracy. Use only as revision-focus signals.
- 2025 Β· 2
Goodness of fit for uniform distribution
- 2024 Β· 1
Independence test for 3x3 contingency table
- 2023 Β· 2
Goodness of fit for normal distribution
Going deeper
What's Next
Chi-squared tests are one of the most frequently tested topics in IB Math AI HL statistics, appearing on both Paper 1 and Paper 2 almost every session. They are also widely used in real-world research across social sciences, medicine, and business, forming the foundation for more advanced categorical data analysis. Mastering this topic will also reinforce your understanding of core hypothesis testing logic that applies to all other tests you will study. Next, you will move on to hypothesis tests for continuous data, building on the framework you learned here.
