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.

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.

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.

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.

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.

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
χ²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)
fₑ = 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)
fₑ = (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 χ²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.

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.

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

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
Step 1 — State the hypothesesH₀: Students are equally likely to prefer each option (each has probability 1/4). H₁: Students are not equally likely to prefer each option.
2
Step 2 — Calculate expected frequenciesUnder 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
Step 3 — Check validityAll expected frequencies equal 20, which is ≥ 5. ✓ The test is valid.
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
Step 5 — Find degrees of freedomThere are k = 4 categories, so ν = k − 1 = 4 − 1 = 3.
ν = 3
6
Step 6 — Compare to critical value and concludeFrom 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.

Observed frequencies: Chronotype vs. Class Preference
Morning ClassAfternoon ClassRow Total
Early Bird301040
Night Owl204060
Column Total5050100
Test of Independence — Chronotype vs. Class Preference
1
Step 1 — State the hypothesesH₀: Class time preference is independent of chronotype. H₁: Class time preference is not independent of chronotype (i.e., they are associated).
2
Step 2 — Calculate expected frequenciesUsing 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
Step 3 — Check validityAll expected frequencies (20, 20, 30, 30) are ≥ 5. ✓ The test is valid.
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
Step 5 — Find degrees of freedomThe table has r = 2 rows and c = 2 columns (excluding totals), so ν = (2 − 1)(2 − 1) = 1.
ν = 1
6
Step 6 — Compare to critical value and concludeFrom 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.

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.

Strengths and limitations of the chi-squared test
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.
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.

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.

How AHL 4.10 connects to more advanced statistical methods
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)

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.

Practice Problems

PROBLEM 1CONCEPTUAL
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.
PROBLEM 2BASIC 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₀?
PROBLEM 3INTERMEDIATE
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)
PROBLEM 4APPLIED
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)
PROBLEM 5CRITICAL 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?

Summary — Chi-Squared Tests

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