Chi-squared Test for Independence (DP IB Applications & Interpretation (AI): SL): Revision Note

Dan Finlay

Written by: Dan Finlay

Reviewed by: Roger B

Updated on

Guided study available on this topic

Understand this topic with deeper explanations and understanding checks.

Chi-Squared Test for Independence

What is a chi-squared test for independence?

  • A chi-squared (χ2) test for independence is a hypothesis test used to test whether two variables are independent of each other

    • This is sometimes called a χ2 two-way test

  • This is an example of a goodness of fit test

    • We are testing whether the data fits the model that the variables are independent

  • The chi-squared (χ2) distribution is used for this test

  • You will use a contingency table

    • This is a two-way table that shows the observed frequencies for the different combinations of the two variables

      • For example: if the two variables are hair colour and eye colour then the contingency table will show the frequencies of the different combinations

What are the degrees of freedom?

  • There will be a minimum number of expected values you would need to know in order to be able to calculate all the expected values

  • This minimum number is called the degrees of freedom and is often denoted by ν

  • For a test for independence with an m × n contingency table

    • ν=(m−1)×(n−1) 

    • For example: If there are 5 rows and 3 columns then you only need to know 2 of the values in 4 of the rows as the rest can be calculated using the totals

What are the steps for a chi-squared test for independence?

  • STEP 1
    Write the hypotheses

    • H0 : Variable X is independent of variable Y

    • H1 : Variable X is not independent of variable Y

      • Make sure you clearly write what the variables are and don’t just call them X and Y

  • STEP 2
    Calculate the degrees of freedom for the test

    • For an m × n contingency table

      • the degrees of freedom is ν=(m−1)×(n−1)

  • STEP 3
    Enter your observed frequencies into your GDC using the option for a 2-way test

    • Enter these as a matrix

    • Your GDC will give you a matrix of the expected values (assuming the variables are independent)

    • Your GDC will also give you the χ² statistic and its p-value

    • The χ² statistic is denoted as χcalc2

  • STEP 4
    Decide whether there is evidence to reject the null hypothesis

    • EITHER compare the χ² statistic with the given critical value

      • If χ² statistic > critical value then reject H0

      • If χ² statistic < critical value then accept H0

    • OR compare the p-value with the given significance level

      • If p-value < significance level then reject H0

      • If p-value > significance level then accept H0

  • STEP 5
    Write your conclusion

    • If you reject H0

      • There is sufficient evidence to suggest that variable X is not independent of variable Y

      • Therefore this suggests they are associated

    • If you accept H0

      • There is insufficient evidence to suggest that variable X is not independent of variable Y

      • Therefore this suggests they are independent

How do I calculate the chi-squared statistic?

  • You are expected to be able to use your GDC to calculate the χ² statistic by inputting the matrix of the observed frequencies

  • Seeing how it is done by hand might deepen your understanding but you are not expected to use this method

  • STEP 1:
    For each observed frequency Oi calculate its expected frequency Ei

    • Assuming the variables are independent

      • Ei = P(X = x) × P(Y = y) × Total

      • Which simplifies to Ei=Row Total × Column TotalOverall Total

  • STEP 2:
    Calculate the χ² statistic using the formula

    • χcalc2=∑(Oi−Ei)2Ei

    • You do not need to learn this formula as your GDC calculates it for you

  • To calculate the p-value you would find the probability of a value being bigger than your χ² statistic using a χ² distribution with ν degrees of freedom

Examiner Tips and Tricks

Note for Internal Assessments (IA)

If you use a χ² test in your IA then be aware that the outcome may not be accurate if:

  • Any of the expected values are less than 5

  • There is only 1 degree of freedom

    • This means it is a 2 × 2 contingency table

Note that none of these cases will occur in the exam.

Worked Example

At a school in Paris, it is believed that favourite film genre is related to favourite school subject.  500 students were asked to indicate their favourite film genre and favourite school subject from a selection and the results are indicated in the table below.

 

Comedy

Action

Romance

Thriller

Maths

51

52

37

55

Sports

59

63

41

33

Geography

35

31

28

15

It is decided to test this hypothesis by using a χ2 test for independence at the 1% significance level. 

The critical value is 16.812.

a) State the null and alternative hypotheses for this test.

Answer:

4-7-2-ib-ai-sl-chi-squared-ind-a-we-solution

b) Write down the number of degrees of freedom for this table.

Answer:

4-7-2-ib-ai-sl-chi-squared-ind-b-we-solution

c) Calculate the χ2 test statistic for this data.

Answer:

4-7-2-ib-ai-sl-chi-squared-ind-c-we-solution

d) Write down the conclusion to the test. Give a reason for your answer.

Answer:

4-7-2-ib-ai-sl-chi-squared-ind-d-we-solution

Unlock more, it's free!

Join the 100,000+ Students that ❤️ Save My Exams

the (exam) results speak for themselves:

Build on this topic

Questions students ask about Chi-squared Test for Independence

Real questions from students revising this topic on Save My Exams

How do you find the critical value for a chi-squared test?

You don't work the critical value out yourself — it is given in the question, so your job is to compare your χ² statistic with it.

Using the critical value

  • If χ²calc > critical value, reject H₀
  • If χ²calc < critical value, accept H₀

If you're given a significance level instead, use the p-value from your GDC:

  • p-value < significance level → reject H₀
  • p-value > significance level → accept H₀

Worked example (from this page): favourite subject vs favourite film genre, a 3 × 4 table at the 1% significance level, critical value 16.812.

  1. ν = (3 − 1) × (4 − 1) = 6
  2. GDC gives χ²calc = 12.817... = 12.8 (3 s.f.)
  3. 12.8 < 16.812, so accept H₀
  4. There is insufficient evidence to suggest favourite subject is not independent of favourite film genre

Why ν matters: a critical value depends on both the significance level and the degrees of freedom, so always work ν out correctly. The p-value method agrees here: p = 0.046 > 0.01.

How do you calculate expected frequencies in a chi-squared test?

Expected frequency = (row total × column total) ÷ overall total — the frequency you'd expect in that cell if the two variables were independent.

It comes from E = P(X = x) × P(Y = y) × total, which simplifies to that formula.

In the exam: enter the observed frequencies into your GDC as a matrix and run the 2-way χ² test — it produces the whole matrix of expected values for you. You may still be asked for one by hand.

By hand

  1. Add up each row and each column of the observed table.
  2. Find the overall total.
  3. For each cell: row total × column total ÷ overall total.

Worked example (from this page): 500 students, favourite subject vs favourite film genre.

  • Maths row total: 51 + 52 + 37 + 55 = 195
  • Comedy column total: 51 + 59 + 35 = 145
  • E(Maths, Comedy) = 195 × 145 ÷ 500 = 56.55

The observed value was 51, slightly below what independence predicts. Expected values don't have to be whole numbers.

Should row and column totals be included when calculating degrees of freedom or entering data for a chi-squared test?

No — leave out any total row or total column, and count only the rows and columns of actual data, both for the degrees of freedom and for the matrix you enter into your GDC.

Degrees of freedom

  • ν = (m − 1) × (n − 1), where m and n are the numbers of data rows and data columns
  • A totals row or column isn't a category of either variable, so it doesn't count

On your GDC

  • Enter only the observed frequencies, with no totals
  • Include them and the GDC treats them as extra categories, giving the wrong degrees of freedom and p-value

Worked example (from this page): favourite subject (Maths, Sports, Geography) vs film genre (Comedy, Action, Romance, Thriller)

  • Enter the 3 × 4 matrix: 51, 52, 37, 55 / 59, 63, 41, 33 / 35, 31, 28, 15
  • ν = (3 − 1) × (4 − 1) = 6
  • χ²calc = 12.8 < 16.812, so accept H₀

Include a totals row and column and you'd have a 4 × 5 table with ν = 12 — wrong.

Totals are still useful for expected frequencies by hand.

Dan Finlay

Author: Dan Finlay

Expertise: Portfolio Lead

Dan graduated from the University of Oxford with a First class degree in mathematics. As well as teaching maths for over 8 years, Dan has marked a range of exams for Edexcel, tutored students and taught A Level Accounting. Dan has a keen interest in statistics and probability and their real-life applications.

Roger B

Reviewer: Roger B

Expertise: Development Editor

Roger's teaching experience stretches all the way back to 1992, and in that time he has taught students at all levels between Year 7 and university undergraduate. Having conducted and published postgraduate research into the mathematical theory behind quantum computing, he is more than confident in dealing with mathematics at any level the exam boards might throw at you.