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.
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.
Observed vs. Expected Frequencies
The Null Hypothesis (H₀)
Degrees of Freedom (ν)
Significance Level (α)
Conditions for Validity
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.
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.
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 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:
Making the Decision
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.
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.
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 Class | Afternoon Class | Row Total | |
|---|---|---|---|
| Early Bird | 30 | 10 | 40 |
| Night Owl | 20 | 40 | 60 |
| Column Total | 50 | 50 | 100 |
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 | Limitations |
|---|---|
| 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. |
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.
| Feature | AHL 4.10 (This Topic) | Advanced Extensions |
|---|---|---|
| Test types | Goodness-of-fit; Test of independence | Homogeneity; McNemar's test; Fisher's exact test |
| Data type | Categorical (counts/frequencies) | Categorical; also extended to ordinal and multinomial data |
| Effect size | Not covered | Cramér's V measures strength of association |
| Sample size issues | Combine categories if fₑ < 5 | Fisher's exact test for very small samples; simulation methods |
| Related distributions | Chi-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.
Practice Problems
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.