In this guide
← Maths AI guides

Statistics & probability · AI SL & HL

Chi-square tests of independence

Work through a chi-square test of independence: build the expected-frequency table, find the statistic and p-value on a GDC, and write a conclusion in context.

Course focus: AI SL & HL · First-assessment-2021 course. The sections distinguish the mathematical idea, the calculation and its interpretation.

Before you start: Two-way tables, probabilities, proportions and hypothesis-test vocabulary.

Start with a small example

Build it from the beginning

A contingency table counts observations in categories of two variables. Under independence, each row has the same category proportions as the whole sample. Expected counts therefore come from row and column totals, not from guessing what looks balanced.

A first walkthrough

In a table of 100 observations, one row total is 40 and one column total is 30. Find their cell expected count under independence.

  1. The column contains 30% of all observations.
  2. Under independence, 30% of the 40 observations in the row should be in that column.
  3. The expected count is \(40(30)/100=12\).
Try the practice ladder after learning the methods ↓

The foundations behind the method

Understand what the symbols mean

An independence test asks whether category proportions change across groups beyond what sampling variation would plausibly explain. The data are counts of individuals in a two-way classification. The null model preserves the observed marginal totals but removes an association between row and column labels.

How the ideas connect

Expected frequencies express the null model, not a prediction that every observed cell will match exactly. Standardizing and summing their discrepancies yields one nonnegative statistic. The p-value then assesses that statistic under the null distribution; it is not the probability that independence is true.

01

Start with the idea

Build your understanding

Null table

Independence means joint proportions factor into marginal proportions, not that categories are equally common.

Evidence

A large discrepancy can provide statistical evidence, but sampling design controls the population to which it applies.

Compare the approaches

Choose by the information in the question, rather than the formula you recognise first.

Independence test

When it helpsUse for two categorical variables in a two-way count table.

Check before using itDo not apply it directly to measurements or percentages without the underlying counts.

Goodness-of-fit test

When it helpsUse for one categorical variable compared with specified category probabilities.

Check before using itIts expected counts and degrees of freedom follow a different setup.

Your method plan

  1. State hypotheses, sampling conditions and significance level.
  2. Construct expected counts and calculate the statistic with its degrees of freedom.
  3. Compare the right-tail p-value and write a contextual conclusion.
02

Learn the methods

Learn step by step

1. Use counts of categorical observations

The test concerns association between two categorical variables. Each observation belongs to one row category and one column category. Use frequency counts, not percentages, measurement means or already-calculated probabilities. Categories should be mutually exclusive within each variable. Observations must be independent in the sampling design; repeated responses from the same person can invalidate an ordinary independence test. A numerical variable needs a justified categorization before this method is appropriate.

2. State the hypotheses about the population

The null hypothesis states that the two variables are independent in the population. The alternative states that they are associated, without specifying a direction in the usual omnibus test. This is different from assuming all cells have equal probability. Independence permits unequal row and column frequencies; it requires the joint proportions to factor into their marginal proportions. Choose a significance level before using the result to make a decision.

3. Construct expected frequencies

Under independence, a cell probability is the product of its row and column proportions. Multiply by total sample size to obtain the expected count. Thus \(E_{ij}=R_iC_j/N\). Expected counts need not be integers; retain their precision. The expected table should reproduce the observed row and column totals. Check the expected counts against the conditions specified by the course or task; very small expectations may require justified category pooling or another method. For the first-assessment-2021 IB examination course, expected frequencies are greater than 5. Check expected counts rather than observed counts; do not merge unrelated categories simply to force the condition.

Observed and expected counts are separate tables

Observed counts
GroupYesNo
A3020
B2030
Expected under independence
GroupYesNo
A2525
B2525
Observed counts 30,20,20,30 share row and column totals of 50. Independence predicts 25 in each cell. Each squared discrepancy contributes 1, giving χ²=4 with one degree of freedom.

Expected cell count

Why this formula works

Under independence, the conditional column proportion is the same in each row. Multiplying a row total by the overall column proportion gives its expected cell count. This keeps every table margin intact while expressing the null relationship, so expected entries are not obtained by simply dividing the grand total equally.

The formula

\(E_{ij}=\frac{R_iC_j}{N}\).

Quick example

A row total 50, column total 40 and grand total 100 give expected count 20.

Worked example: Unequal margins do not mean dependence

Observed counts are \(\begin{pmatrix}12&18\\28&42\end{pmatrix}\).

  1. Rows total 30 and 70; columns total 40 and 60; N=100.
  2. The expected cells from the margins are exactly 12,18,28,42.
  3. The statistic is zero because every observed count equals its expectation.
  4. The observed row proportions are unequal, but the column proportion is 40% in both rows. This table illustrates the null pattern, not an equal-cell pattern.

4. Accumulate standardized discrepancies

Each cell contributes \((O-E)^2/E\). Squaring prevents positive and negative differences from cancelling, while dividing by E scales the discrepancy relative to expected size. Sum across every cell, not only conspicuous ones. A large statistic suggests the table is unusual under independence. The reference chi-square distribution is right-skewed, and the p-value comes from its right tail, not from a two-tailed normal calculation.

5. Degrees of freedom and decision

For r rows and c columns, the usual degrees of freedom are \((r-1)(c-1)\). With fixed margins, the remaining cells follow from the free ones. Obtain the right-tail p-value or compare to an appropriate critical value. Reject when p is at or below the chosen significance level using the course convention. Otherwise say insufficient evidence to reject, not that the variables have been proved independent.

Statistic and degrees of freedom

Why this formula works

The standardized squared differences quantify departure from the null table. With row and column totals fixed, choosing the first r minus one rows and c minus one columns determines the remaining cells. This number of independent choices gives the distribution’s degrees of freedom.

The formula

\(\chi^2=\sum\frac{(O-E)^2}{E}\) \(\nu=(r-1)(c-1)\).

Quick example

A 2 by 3 table has two degrees of freedom. Its p-value is \(P(\chi^2_2\ge\chi^2_{\rm observed})\).

Worked example: Study preference and year group: a complete test

A random sample of 100 students is classified by year group (rows: Year 1, Year 2) and preferred study format (columns: individual, group). Observed counts are \(\begin{pmatrix}30&20\\20&30\end{pmatrix}\). Each student responds once. Test for association at the 5% significance level.

  1. State \(H_0\): year group and preferred study format are independent in the sampled population. State \(H_1\): they are associated. Set \(\alpha=0.05\).
  2. Both row totals and both column totals are 50; N=100. Every expected count is 50×50/100=25. All expected counts are greater than 5, and each student supplies one observation.
  3. Each cell contributes \((30-25)^2/25=1\) or \((20-25)^2/25=1\). Thus \(\chi^2=4\), with \((2-1)(2-1)=1\) degree of freedom.
  4. Enter the observed 2×2 table into the GDC chi-square independence test. Check that it returns statistic 4, one degree of freedom and right-tail p-value approximately 0.04550. Do not enter the expected table as the observations.
  5. Since 0.04550<0.05, reject the null hypothesis. There is evidence of an association between year group and preferred study format in the population represented by the sample.
  6. This does not show that year group causes the preference. The p-value is not the probability that the null hypothesis is true.
Worked example: Expected counts with unequal row totals

Observed counts are \(\begin{pmatrix}15&5\\15&25\end{pmatrix}\). Calculate the independence statistic.

  1. Rows total 20 and 40; both columns total 30; N=60.
  2. Expected counts are \(\begin{pmatrix}10&10\\20&20\end{pmatrix}\).
  3. Contributions are 2.5,2.5,1.25,1.25, giving \(\chi^2=7.5\).
  4. Use one degree of freedom. The statistic exceeds the 5% critical value about 3.84146, so the result is evidence against independence under the test assumptions.
Worked example: A two-by-three table and a different degree of freedom

A sample is classified by travel group (rows: A, B) and transport choice (columns: bus, walk, cycle). Observed counts are \(\begin{pmatrix}30&20&10\\10&20&30\end{pmatrix}\). Assuming independent observations and a suitable sampling design, test independence at 5%.

  1. Each row totals 60. Each column totals 40. The grand total is 120, so every expected count is 60×40/120=20. All six expected counts are greater than 5.
  2. The six contributions are 5, 0, 5, 5, 0, 5, so \(\chi^2=20\).
  3. There are \((2-1)(3-1)=2\) degrees of freedom, not 1. The GDC right-tail p-value is approximately 0.0000454.
  4. Reject independence at 5%. There is evidence of association between travel group and transport choice in the population represented by the sample.
  5. The larger degrees of freedom change the reference distribution. Never reuse the p-value or critical value from a 2×2 example for a table with different dimensions.

6. Interpret association without causation

A significant result identifies evidence of association, not the size, direction or cause of that association. Inspect which cells contribute most to the statistic to explain the pattern cautiously. A large sample can make a small difference statistically detectable. The design and population sampled determine where the conclusion applies. State variable names and context, rather than merely writing “reject H0.” A failure to reject may reflect limited power as well as a genuinely small association.

Quick formula reference

For revision once you understand the methods above. Check the conditions before using a formula.

Expected cell count

\(E_{ij}=\frac{R_iC_j}{N}\).

Return to the explanation →

Statistic and degrees of freedom

\(\chi^2=\sum\frac{(O-E)^2}{E}\), \(\nu=(r-1)(c-1)\).

Return to the explanation →

Learn to diagnose an error

Spot the mistake

The statement below is incorrect. Identify the missing condition or reasoning before opening the explanation.

Incorrect reasoning

A chi-square independence test always expects the same count in every cell.

Explain and repair the mistake

Expected counts depend on the margins. A large row or common column has larger expected cells. Equal expected cells arise only with suitable equal margins; use row total times column total divided by the grand total.

03

Connect and apply

Put the ideas together

A more demanding application of this guide’s methods. This is a learning stage; any additional HL content is labelled separately.

Worked application

The same p-value can produce different decisions

A table gives p=0.0455. Compare decisions at 5% and 1%.

  1. At 5%, 0.0455 is below 0.05, so reject the null.
  2. At 1%, it is above 0.01, so do not reject.
  3. The data and p-value have not changed; the preselected decision threshold has.
  4. Report the chosen level and avoid selecting it after seeing the result merely to obtain significance.
Pause and explain

Does non-rejection at 1% prove independence?

Check your reasoning

No. It means the evidence does not meet that more demanding threshold under the stated test. The p-value measures compatibility under the null, not a posterior probability that it is true.

Common mistakes and how to avoid them

  • Expected counts depend on the margins. A large row or common column has larger expected cells. Equal expected cells arise only with suitable equal margins; use row total times column total divided by the grand total.
  • Do not apply it directly to measurements or percentages without the underlying counts.
  • Its expected counts and degrees of freedom follow a different setup.
04

Practise independently

Build confidence, then apply it

Try each question before opening its hint or solution. If a method is new, return to the walkthrough, then try again. These learning stages describe the practice sequence; additional HL content is labelled separately.

  1. 1

    Build confidence

    For row total 25 and column total 60 in the same sample, find the expected count.

    Need a starting point?

    Use row total times column total divided by grand total.

    Show the worked solution
    1. \(E=25(60)/100\).
    2. The expected count is 15.
  2. 2

    Apply and explain

    A test gives p=0.03 at significance level 0.05. State the decision.

    Need a starting point?

    Compare p with the chosen significance level.

    Show the worked solution
    1. Since \(0.03<0.05\), reject the independence null hypothesis.
    2. There is evidence of association; the test does not establish causation.
  3. 3

    Check your understanding

    A row total is 20, a column total is 30 and the grand total is 100. Find their expected cell count.

    Show the worked solution

    The expectation under independence is 20×30/100=6. It is not obtained by dividing the grand total by the number of table cells unless the margins happen to justify that.

  4. 4

    Use the method

    What are the usual degrees of freedom for a 3 by 4 table?

    Show the worked solution

    They are (3−1)(4−1)=6. Use this value with the right-tail chi-square distribution after checking that the table and expected-count conditions are appropriate.

Finished? Use the linked question bank below to practise selecting the method without a guide telling you which rule to use.

Using these methods in exam questions

AI Paper 1

GDC required

Short-response questions still need mathematical setup and interpretation. Choose the correct tool, enter the model or data carefully, and check units and rounding.

AI Paper 2

GDC required

Extended-response questions connect several steps. Keep intermediate values at full precision and explain how each result answers the context.

For this topic: Define the variable or events, write the probability statement or hypotheses, then calculate. Name the distribution and its parameters; interpret the result using the original population or context.

HL only · GDC required

Paper 3: build a connected argument

Both AA HL and AI HL Paper 3 contain two extended problem-solving questions. A question develops a theme, so keep useful earlier results, test small cases and explain any proposed general rule. A calculator pattern can suggest a result; your mathematical reasoning must support it.

  1. Identify what the first part establishes and record the conditions under which it holds.
  2. When a later part introduces a new definition or model, connect it to methods you already know rather than assuming a new formula must have been memorised.
  3. Check the conclusion against an earlier numerical case and explain its meaning or limitation.

For the first-assessment-2021 courses. IB assessment reference ↗

Find a specific method or formula

Now practise the method

If you opened this guide from a question, return to that tab and try the method without looking at the example. Your answer stays in the question tab.

Practise this subtopic →

Want a broader practice session? Explore IB Maths AI SL practice questions →Explore IB Maths AI HL practice questions →Try free IB Maths exam-style questions and worked solutions →

Original Arc Practice teaching notes for Maths AI. Core and HL sections are distinguished above. These notes follow the first-assessment-2021 course and are not an official IB publication or a complete syllabus checklist. IB course reference. Report a correction.