Study Guide

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

πŸ“˜ Definition

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:

Ο‡2=βˆ‘(Oβˆ’E)2E\chi^2 = \sum \frac{(O - E)^2}{E}
πŸ“ Worked Example

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. 1

    First calculate expected frequencies by multiplying total sample size by the hypothesized proportion for each category:

  2. 2
    EO=200Γ—0.45=90,EA=200Γ—0.40=80,EB=200Γ—0.11=22,EAB=200Γ—0.04=8E_O = 200 \times 0.45 = 90,\quad E_A = 200 \times 0.40 = 80,\quad E_B = 200 \times 0.11 = 22,\quad E_{AB} = 200 \times 0.04 = 8
  3. 3

    Calculate the term for each category:

  4. 4
    (92βˆ’90)290β‰ˆ0.044,(75βˆ’80)280=0.3125,(24βˆ’22)222β‰ˆ0.1818,(9βˆ’8)28=0.125\frac{(92-90)^2}{90} \approx 0.044,\quad \frac{(75-80)^2}{80} = 0.3125,\quad \frac{(24-22)^2}{22} \approx 0.1818,\quad \frac{(9-8)^2}{8} = 0.125
  5. 5

    Sum all terms to get the final test statistic:

  6. 6
    Ο‡2β‰ˆ0.044+0.3125+0.1818+0.125=0.663\chi^2 \approx 0.044 + 0.3125 + 0.1818 + 0.125 = 0.663

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.

πŸ“˜ Definition

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

πŸ“ Worked Example

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. 1

    Identify the values for (number of categories) and (number of estimated parameters):

  2. 2
    n=6,k=0n = 6,\quad k = 0
  3. 3

    Apply the degrees of freedom formula:

  4. 4
    Ξ½=6βˆ’0βˆ’1=5\nu = 6 - 0 - 1 = 5

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.

πŸ“˜ Definition

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:

E=Row TotalΓ—Column TotalGrand TotalE = \frac{\text{Row Total} \times \text{Column Total}}{\text{Grand Total}}

Degrees of freedom for a test of independence is always calculated as:

Ξ½=(rβˆ’1)(cβˆ’1)\nu = (r - 1)(c - 1)
πŸ“ Worked Example

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. 1

    Identify the number of rows and columns :

  2. 2
    r=3,c=2r = 3,\quad c = 2
  3. 3

    Apply the degrees of freedom formula for independence:

  4. 4
    Ξ½=(3βˆ’1)(2βˆ’1)=2Γ—1=2\nu = (3 - 1)(2 - 1) = 2 \times 1 = 2
βœ“ Quick check

Check your understanding:

  1. 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.