← Back to course

Chi-Square Test for Independence

You’ll be able to

One sample, two variables

A chi-square test for independence uses a single sample and asks whether two categorical variables measured on it are associated. H₀: the two variables are independent (no association) in the population; Hₐ: they are associated. Example: draw one random sample of students and record both their grade level and their preferred learning style, then test whether the two are related.

The statistic and degrees of freedom

Compute χ² = Σ (observed − expected)²/expected over all cells, with expected counts from the row×column/total formula. For a two-way table the degrees of freedom = (rows − 1)(columns − 1). A large χ² gives a small p-value and evidence of association. Conditions: Random sample, Large Counts (all expected ≥ 5), and 10% for independence of individuals.

Chi-square test for a two-way table
χ² = Σ (observed − expected)² / expected · df = (r − 1)(c − 1)
Here r is the number of rows and c the number of columns. A 3×4 table has df = (3−1)(4−1) = 6. Always upper-tailed.
Worked example

A single random sample of adults is classified by exercise level (3 categories) and stress level (3 categories). The chi-square statistic is 18.2. Find the degrees of freedom and describe how to reach a conclusion at α = 0.05.

  1. 1.This is a test for independence (one sample, two variables). H₀: exercise and stress levels are independent; Hₐ: they are associated.
  2. 2.Degrees of freedom: df = (r − 1)(c − 1) = (3 − 1)(3 − 1) = 2 × 2 = 4.
  3. 3.Find the p-value as the area to the right of χ² = 18.2 under the chi-square distribution with df = 4 (p-value ≈ 0.001).
  4. 4.Since the p-value < 0.05, reject H₀.
Answer: df = (3−1)(3−1) = 4, and χ² = 18.2 gives a p-value ≈ 0.001 < 0.05, so we reject H₀. There is convincing evidence of an association between exercise level and stress level among these adults.
Checkpoint

A chi-square test is applied to a two-way table with 4 rows and 3 columns. How many degrees of freedom does it have?

Watch out

A chi-square test can establish an association, but on its own it never establishes causation — the data come from an observational classification, not a randomized experiment. Conclude "there is evidence of an association," not "one variable causes the other."

Checkpoint

A chi-square test for independence yields a very small p-value. What is the correct conclusion?

Answer the 2 checkpoints as you read.

Sign in to save your progress