IB Mathematics: Applications and Interpretation • Statistics and Probability

Chi-Squared Tests — AHL 4.10 Chi-squared tests (goodness-of-fit/independence) (HL) (intro)

Learn how to test whether observed data fit a model or whether two categorical variables are truly independent.

IB Mathematics Applications and Interpretation emblem with a scatter plot, calculator, and data chart
Inside this lesson 10 sections 5 questions 9 figures

SECTION 1

Historical Context & Motivation

In statistics, we often collect data and wonder: does this data match what we expected? For example, if you roll a die 60 times, you'd expect each face to appear roughly 10 times. But what if one face shows up 18 times — is the die rigged, or is that just random luck? The chi-squared test (written χ²) is the statistical tool that answers this kind of question. It measures how far observed data deviate from what a theoretical model predicts, and it tells us whether the difference is statistically significant or just due to chance.

The development of the chi-squared test is rooted in the practical needs of scientists and social researchers who needed a reliable method for testing hypotheses about categorical (count-based) data. Unlike methods that deal with measurements and averages, chi-squared works with frequencies — how often things fall into different categories.

1900 • Karl Pearson's Breakthrough

Karl Pearson publishes his landmark paper introducing the chi-squared goodness-of-fit test, providing the first rigorous method for comparing observed frequencies to expected frequencies in categorical data.

1922 • Ronald Fisher Refines the Method

R. A. Fisher corrects Pearson's formula by introducing the concept of degrees of freedom, which properly accounts for the number of independent pieces of information in the data. This refinement makes the test far more accurate.

1934 • Test of Independence Formalized

The chi-squared test of independence becomes a standard tool for analyzing two-way contingency tables, allowing researchers to determine whether two categorical variables are related.

1950s–today • Widespread Adoption

Chi-squared tests become fundamental across biology, medicine, social science, market research, and quality control. With modern technology, they are now built into every major statistics software package and are a cornerstone of the IB Mathematics curriculum.

The central question the chi-squared test addresses is deceptively simple: Is the difference between what we observed and what we expected large enough to be meaningful, or could it have happened by chance? This question arises whenever we deal with categorical data — data sorted into groups or categories rather than measured on a continuous scale.

SECTION 2

Core Principles & Definitions

Before diving into calculations, you need to understand several foundational ideas that underpin both types of chi-squared test. These principles explain what the test measures, what assumptions it requires, and how you interpret its results.

1

Observed vs. Expected Frequencies

Observed frequencies (fo) are the actual counts you collect from your data. Expected frequencies (fe) are the counts you would predict if the null hypothesis were true. The chi-squared statistic measures the gap between these two.
2

The Null Hypothesis (H₀)

Every chi-squared test starts with a null hypothesis. For goodness-of-fit: 'The data follow the proposed distribution.' For independence: 'The two variables are independent (not associated).' You either reject or fail to reject H₀.
3

Degrees of Freedom (ν)

Degrees of freedom determine which chi-squared distribution you compare your test statistic against. For goodness-of-fit: ν = k − 1 (where k = number of categories). For independence: ν = (r − 1)(c − 1) where r and c are the numbers of rows and columns.
4

Significance Level (α)

The significance level is the threshold for deciding whether to reject H₀. In the IB, this is typically α = 0.05 (5%), unless stated otherwise. If the p-value < α, you reject H₀.
5

Conditions for Validity

The chi-squared test requires that all expected frequencies be at least 5. If any expected frequency falls below 5, you should combine adjacent categories. The data must also consist of independent observations from a random sample.
✦

KEY TAKEAWAY

Think of the chi-squared test like a quality inspector at a candy factory. The factory claims each bag has equal numbers of red, blue, green, and yellow candies. The inspector opens a bag and counts each color. If the counts are close to equal, the claim passes. If one color massively dominates, the inspector rejects the claim. The chi-squared statistic is like a single number that summarizes how far off the bag is from the ideal mix — the bigger the number, the worse the mismatch.

SECTION 3

Visual Explanation — Two Types of Chi-Squared Tests

The diagram below contrasts the two chi-squared tests you need to know for the IB HL course. On the left is the goodness-of-fit test, which checks whether a single categorical variable matches a theoretical distribution. On the right is the test of independence, which checks whether two categorical variables are related. Both tests use the same χ² formula, but they set up expected frequencies differently.

Two Types of Chi-Squared TestsGoodness-of-Fit TestTest of IndependenceOne categorical variableTwo categorical variablesQuestion:"Does this data fit theproposed distribution?"Question:"Are these two variablesindependent of each other?"Data layout:Cat 1Cat 2Cat 3...Observed counts (one row)Data layout:B₁B₂B₃A₁12815A₂52010Degrees of freedom:ν = k − 1(k = number of categories)Degrees of freedom:ν = (r − 1)(c − 1)(r = rows, c = columns)H₀:Data follows the proposeddistribution.H₀:The two variables areindependent.Same Formula:χ² = Σ (fₒ − fₑ)² / fₑ
Both tests use the same χ² formula but differ in how they set up the problem. The goodness-of-fit test uses a single row of categories, while the test of independence uses a two-way table (contingency table) with rows and columns representing two different variables.

Notice in the diagram that the goodness-of-fit test works with a single row of observed counts compared to a single row of expected counts. The test of independence, by contrast, uses a full grid (contingency table) where each cell represents the count of observations that fall into a specific combination of two categories. Despite this structural difference, both tests funnel their data through the same χ² calculation, making the underlying logic remarkably consistent.

SECTION 4

Mathematical Framework

The mathematical heart of both chi-squared tests is a single formula. Understanding this formula and how expected frequencies are calculated for each test type is essential for success in the IB exam.

CHI-SQUARED TEST STATISTIC

χ2calc=Σ(fo−fe)2/feχ²calc = Σ (fₒ − fₑ)² / fₑ

Where fₒ = observed frequency (actual count), fₑ = expected frequency (predicted count under H₀), and Σ means you sum over all categories. Each term (fₒ − fₑ)² / fₑ measures that category's contribution to the overall mismatch.

Expected Frequencies for Goodness-of-Fit

In a goodness-of-fit test, the expected frequencies come directly from the theoretical distribution you're testing. If you believe a die is fair, each face has probability 1/6, so the expected count for each face in 60 rolls is 60 × (1/6) = 10. More generally:

EXPECTED FREQUENCY (GOODNESS-OF-FIT)

fe=n×pfₑ = n × p

Where n = total number of observations and p = theoretical probability of that category under H₀.

Expected Frequencies for Independence

In a test of independence, you don't start with a theoretical distribution. Instead, the expected frequencies are calculated from the data itself, using row and column totals. If two variables are truly independent, the expected count in any cell equals:

EXPECTED FREQUENCY (INDEPENDENCE)

fe=(rowtotal×columntotal)/grandtotalfₑ = (row total × column total) / grand total

This formula distributes the data proportionally across cells, reflecting what the counts would look like if the two variables had no association. You calculate this for every cell in the contingency table.

Making the Decision

DECISION RULE

Ifχ2calc>χ2critical,rejectH0If χ²calc > χ²critical, reject H₀

Look up χ²critical from the chi-squared distribution table using your degrees of freedom (ν) and significance level (α, usually 0.05). Alternatively, if a p-value is given: reject H₀ when p-value < α.

💡

IB Formula Booklet Reminder

The χ² test statistic formula and the expected frequency formula for independence are both provided in the IB formula booklet. You do not need to memorize them, but you must understand what each variable represents and know how to apply them correctly.

SECTION 5

Step-by-Step Testing Procedure

Both types of chi-squared test follow the same structured procedure. Getting comfortable with this step-by-step process is crucial, because IB examiners award marks for each stage — not just the final answer. The flowchart below maps the full procedure from start to conclusion.

Chi-Squared Test ProcedureStep 1: State H₀ and H₁Step 2: Calculate expected frequenciesStep 3: Check all fₑ ≥ 5(combine categories if needed)Step 4: Calculate χ²calc = Σ(fₒ−fₑ)²/fₑStep 5: Find degrees of freedom (ν)Step 6: Find χ²critical or p-valueχ²calc > χ²crit?or p-value < α?NoFail to reject H₀Yes → Reject H₀Sufficient evidence of associationFail to reject H₀Insufficient evidence
The six-step chi-squared testing procedure. Notice that Step 3 (checking that all expected frequencies are at least 5) is a critical validity check that IB examiners look for. The final decision in Step 6 must always be stated in context — not just 'reject' or 'don't reject,' but what that means for the real-world scenario.
⚠

Writing Your Conclusion (IB Exam Tip)

Never write 'accept H₀.' The correct phrasing is 'fail to reject H₀' or 'there is insufficient evidence to reject H₀.' Then state the conclusion in context, e.g., 'There is insufficient evidence at the 5% significance level to suggest that the die is not fair.'

SECTION 6

Worked Examples

Example 1: Goodness-of-Fit Test

A teacher claims that students are equally likely to prefer each of four lunch options: pizza, pasta, salad, and sandwich. She surveys 80 students and records the following preferences: Pizza = 28, Pasta = 22, Salad = 12, Sandwich = 18. Test at the 5% significance level whether the data support the teacher's claim.

Goodness-of-Fit Test — Lunch Preferences

  1. 1

    Step 1 — State the hypotheses

    H₀: Students are equally likely to prefer each option (each has probability 1/4). H₁: Students are not equally likely to prefer each option.
  2. 2

    Step 2 — Calculate expected frequencies

    Under H₀, each category has probability 1/4. With n = 80 students: fₑ = 80 × (1/4) = 20 for each option. So the expected frequencies are: Pizza = 20, Pasta = 20, Salad = 20, Sandwich = 20.
    fₑ = 20 for each category
  3. 3

    Step 3 — Check validity

    All expected frequencies equal 20, which is ≥ 5. ✓ The test is valid.
  4. 4

    Step 4 — Calculate χ²calc

    χ²calc = (28 − 20)²/20 + (22 − 20)²/20 + (12 − 20)²/20 + (18 − 20)²/20 = 64/20 + 4/20 + 64/20 + 4/20 = 3.2 + 0.2 + 3.2 + 0.2
    χ²calc = 6.8
  5. 5

    Step 5 — Find degrees of freedom

    There are k = 4 categories, so ν = k − 1 = 4 − 1 = 3.
    ν = 3
  6. 6

    Step 6 — Compare to critical value and conclude

    From the χ² table with ν = 3 and α = 0.05: χ²critical = 7.815. Since χ²calc = 6.8 < 7.815 = χ²critical, we fail to reject H₀. There is insufficient evidence at the 5% significance level to conclude that students' lunch preferences are not equally distributed.
    6.8 < 7.815 → Fail to reject H₀

Example 2: Test of Independence

A survey asks 100 students whether they prefer morning or afternoon classes and whether they consider themselves 'early birds' or 'night owls.' The results are shown below. Test at the 5% significance level whether class time preference is independent of chronotype.

Morning ClassAfternoon ClassRow Total
Early Bird301040
Night Owl204060
Column Total5050100

Observed frequencies: Chronotype vs. Class Preference

Test of Independence — Chronotype vs. Class Preference

  1. 1

    Step 1 — State the hypotheses

    H₀: Class time preference is independent of chronotype. H₁: Class time preference is not independent of chronotype (i.e., they are associated).
  2. 2

    Step 2 — Calculate expected frequencies

    Using fₑ = (row total × column total) / grand total: Early Bird & Morning = (40 × 50)/100 = 20. Early Bird & Afternoon = (40 × 50)/100 = 20. Night Owl & Morning = (60 × 50)/100 = 30. Night Owl & Afternoon = (60 × 50)/100 = 30.
    Expected: 20, 20, 30, 30
  3. 3

    Step 3 — Check validity

    All expected frequencies (20, 20, 30, 30) are ≥ 5. ✓ The test is valid.
  4. 4

    Step 4 — Calculate χ²calc

    χ²calc = (30 − 20)²/20 + (10 − 20)²/20 + (20 − 30)²/30 + (40 − 30)²/30 = 100/20 + 100/20 + 100/30 + 100/30 = 5 + 5 + 3.333 + 3.333
    χ²calc ≈ 16.67
  5. 5

    Step 5 — Find degrees of freedom

    The table has r = 2 rows and c = 2 columns (excluding totals), so ν = (2 − 1)(2 − 1) = 1.
    ν = 1
  6. 6

    Step 6 — Compare to critical value and conclude

    From the χ² table with ν = 1 and α = 0.05: χ²critical = 3.841. Since χ²calc = 16.67 > 3.841 = χ²critical, we reject H₀. There is sufficient evidence at the 5% significance level to conclude that class time preference and chronotype are not independent — they are associated.
    16.67 > 3.841 → Reject H₀. The variables are associated.

SECTION 7

Strengths & Limitations

The chi-squared test is one of the most versatile tools in statistics, but like every method, it has both advantages and constraints. Understanding these will help you decide when the test is appropriate and avoid common pitfalls on the IB exam.

StrengthsLimitations
Works with categorical (non-numeric) data — no need for measurements or averages.Requires all expected frequencies to be at least 5; small samples may need categories combined.
Simple, consistent formula for both goodness-of-fit and independence tests.Only detects association, not causation — a significant result doesn't prove one variable causes the other.
No assumptions about the shape of the underlying distribution (non-parametric).Cannot measure the direction or strength of a relationship — only whether one exists.
Widely applicable across sciences, social sciences, business, and medicine.Sensitive to large sample sizes — very large n can produce statistical significance even for trivially small differences.
Easy to compute by hand or with a GDC (graphing calculator).Data must be independent observations — cannot be used with paired or repeated-measures data.

Strengths and limitations of the chi-squared test

✦

KEY TAKEAWAY

Think of the chi-squared test as a smoke alarm. It can tell you that something is off (there's smoke), but it can't tell you what's burning or how to fix it. Similarly, a significant χ² result tells you that observed data don't match the model or that two variables are associated, but it doesn't explain why or how strongly. For that, you'd need additional analysis.

SECTION 8

Connection to Advanced Theory

The chi-squared tests you learn in AHL 4.10 are introductory applications of a much broader family of hypothesis tests. Understanding where this topic sits in the bigger picture can deepen your understanding and prepare you for further study.

FeatureAHL 4.10 (This Topic)Advanced Extensions
Test typesGoodness-of-fit; Test of independenceHomogeneity; McNemar's test; Fisher's exact test
Data typeCategorical (counts/frequencies)Categorical; also extended to ordinal and multinomial data
Effect sizeNot coveredCramér's V measures strength of association
Sample size issuesCombine categories if fₑ < 5Fisher's exact test for very small samples; simulation methods
Related distributionsChi-squared distribution (χ²)F-distribution (ANOVA), G-test (likelihood ratio)

How AHL 4.10 connects to more advanced statistical methods

In university statistics courses, you'll encounter Cramér's V, which goes beyond asking 'is there an association?' to quantifying how strong it is. You'll also see the chi-squared distribution appear as a building block for ANOVA (analysis of variance) and regression analysis. For now, mastering the two tests in this topic gives you a solid foundation that transfers directly into those advanced methods.

💡

IB Internal Assessment Connection

Chi-squared tests are excellent tools for your Math IA. If your exploration involves survey data or categorical observations — for example, comparing music preferences across age groups, or testing whether dice in a board game are fair — a chi-squared test provides a rigorous way to analyze your findings and demonstrate statistical reasoning.

SECTION 9

Practice Problems

Question 1: CONCEPTUAL

Explain the difference between a chi-squared goodness-of-fit test and a chi-squared test of independence. In your answer, describe what type of data each test analyzes and what the null hypothesis states in each case.
Show answer
A goodness-of-fit test examines whether a single categorical variable follows a proposed theoretical distribution. Its null hypothesis states that the observed data fit the expected distribution. For example, testing whether a die is fair. A test of independence examines whether two categorical variables are associated by analyzing a two-way contingency table. Its null hypothesis states that the two variables are independent. For example, testing whether gender and voting preference are related. Both use the same χ² = Σ(fₒ − fₑ)²/fₑ formula, but they differ in how expected frequencies are calculated and how degrees of freedom are determined.

Question 2: BASIC CALCULATION

A spinner has 5 equal sections. You spin it 100 times and observe: Section A = 24, B = 18, C = 22, D = 16, E = 20. Calculate the χ² test statistic and state the degrees of freedom. The critical value at α = 0.05 with 4 degrees of freedom is 9.488. Should you reject H₀?
Show answer
Under H₀ (fair spinner), each section has expected frequency fₑ = 100/5 = 20. The χ² statistic is: (24−20)²/20 + (18−20)²/20 + (22−20)²/20 + (16−20)²/20 + (20−20)²/20 = 16/20 + 4/20 + 4/20 + 16/20 + 0/20 = 0.8 + 0.2 + 0.2 + 0.8 + 0 = 2.0. The degrees of freedom are ν = 5 − 1 = 4. Since χ²calc = 2.0 < 9.488 = χ²critical, we fail to reject H₀. There is insufficient evidence to suggest the spinner is not fair.

Question 3: INTERMEDIATE

A biologist observes flower colors in a garden and expects a 9:3:3:1 ratio of red:pink:white:yellow based on a genetic model. From 160 flowers observed: Red = 86, Pink = 35, White = 26, Yellow = 13. Perform a chi-squared goodness-of-fit test at the 5% level. (χ²critical for 3 d.f. at 0.05 = 7.815)
Show answer
H₀: The flower colors follow a 9:3:3:1 ratio. H₁: They do not. The expected frequencies are: Red = 160 × 9/16 = 90, Pink = 160 × 3/16 = 30, White = 160 × 3/16 = 30, Yellow = 160 × 1/16 = 10. All expected frequencies are ≥ 5, so the test is valid. χ²calc = (86−90)²/90 + (35−30)²/30 + (26−30)²/30 + (13−10)²/10 = 16/90 + 25/30 + 16/30 + 9/10 = 0.178 + 0.833 + 0.533 + 0.900 = 2.444. With ν = 4 − 1 = 3 and χ²calc = 2.444 < 7.815, we fail to reject H₀. There is insufficient evidence to suggest the flower colors do not follow the 9:3:3:1 genetic ratio.

Question 4: APPLIED

A school surveys 200 students about their study method (flashcards, practice problems, re-reading notes) and exam result (pass, fail). Results: Flashcards: 50 pass, 10 fail. Practice problems: 55 pass, 15 fail. Re-reading: 40 pass, 30 fail. Perform a test of independence at the 5% level. (χ²critical for 2 d.f. at 0.05 = 5.991)
Show answer
H₀: Study method and exam result are independent. H₁: They are not independent. Row totals: Pass = 145, Fail = 55. Column totals: Flashcards = 60, Practice = 70, Re-reading = 70. Grand total = 200. Expected frequencies: Flashcards Pass = (145×60)/200 = 43.5, Flashcards Fail = (55×60)/200 = 16.5, Practice Pass = (145×70)/200 = 50.75, Practice Fail = (55×70)/200 = 19.25, Re-reading Pass = (145×70)/200 = 50.75, Re-reading Fail = (55×70)/200 = 19.25. All fₑ ≥ 5 ✓. χ²calc = (50−43.5)²/43.5 + (10−16.5)²/16.5 + (55−50.75)²/50.75 + (15−19.25)²/19.25 + (40−50.75)²/50.75 + (30−19.25)²/19.25 = 0.971 + 2.561 + 0.356 + 0.939 + 2.274 + 6.003 = 13.104. With ν = (2−1)(3−1) = 2 and χ²calc = 13.104 > 5.991, we reject H₀. There is sufficient evidence at the 5% level to conclude that study method and exam result are not independent — they are associated.

Question 5: CRITICAL THINKING

A researcher collects data on 50 people and creates a 2×4 contingency table. Two of the expected frequencies are 3.2 and 4.1. She proceeds with the chi-squared test and obtains χ²calc = 12.5 with p-value = 0.006, concluding a 'highly significant result.' Critique her approach. What should she have done differently, and how might this affect her conclusion?
Show answer
The researcher violated the validity condition for the chi-squared test: all expected frequencies must be at least 5. Two of her expected frequencies (3.2 and 4.1) fall below this threshold, which means the chi-squared distribution may not be a good approximation for the true sampling distribution of her test statistic. She should have combined adjacent columns (categories) so that all expected frequencies reach at least 5, then recalculated the test with the merged table and correspondingly fewer degrees of freedom. With fewer columns, the degrees of freedom would decrease, which changes the critical value and could alter the conclusion. Additionally, with a small sample of only 50 across 8 cells, Fisher's exact test would be a more appropriate alternative. Her conclusion may still hold after proper adjustments, but presenting it without acknowledging the violated assumption is methodologically flawed and would lose marks on an IB exam.

SUMMARY

Summary — Chi-Squared Tests

Summary

The chi-squared test uses the formula χ² = Σ(fₒ − fₑ)²/fₑ to measure the discrepancy between observed frequencies and expected frequencies. The goodness-of-fit test checks whether one categorical variable matches a theoretical distribution (ν = k − 1), while the test of independence checks whether two categorical variables are associated using a contingency table (ν = (r − 1)(c − 1)). For independence, expected frequencies are calculated as (row total × column total) / grand total.

Both tests require all expected frequencies to be at least 5. If χ²calc exceeds χ²critical (or the p-value is less than the significance level α), you reject H₀. Always state your conclusion in context, and remember: never say 'accept H₀' — instead say 'fail to reject H₀.' The chi-squared test detects association, not causation, and does not measure the strength of a relationship.

Varsity Tutors • IB Mathematics: Applications and Interpretation • Chi-Squared Tests — AHL 4.10