mindstair

Home / Courses / Statistics 2 / Unit 3

Statistics 2 Unit 3: Chi-Square Tests

Chi-square tests handle categorical data: whether counts fit a model, and whether two categorical variables are related. You will compute expected counts, the χ² statistic and its df, and explain which cells drive the result.

Covers: The chi-square distribution, Goodness-of-fit tests, Tests of independence, Tests of homogeneity, Expected counts and conditions, Residuals and follow-up analysis

Study guide

Every chi-square test compares observed counts O with expected counts E calculated as if the null hypothesis were true. The statistic χ² = Σ(O − E)²/E adds up the squared gaps, each scaled by its expected count, so a gap of 10 matters more when E is 20 than when E is 200. Because every term is nonnegative, any departure from H₀ pushes χ² upward, and the p-value is always the right-tail area. The reference distribution is chi-square with the appropriate degrees of freedom; it is right-skewed, starts at 0, and has mean equal to its df.

A goodness-of-fit (GOF) test checks one categorical variable against a hypothesized distribution, such as a fair die, a claimed market share, or a genetic ratio like 9:3:3:1. The expected count in each category is n times the hypothesized proportion. With k categories the test has k − 1 df, because the counts must add to n. If you estimate parameters of the model from the data, such as λ for a Poisson model or μ and σ for a normal model, subtract one more df for each one. Without this adjustment the test is too lenient.

Two-way tables lead to two tests with the same arithmetic. A test of independence uses one random sample classified on two variables and asks whether they are associated. A test of homogeneity uses separate samples from several populations and asks whether the distribution of one variable is the same in each. In both, E = (row total × column total)/grand total and df = (r − 1)(c − 1). For a 2 × 2 table, χ² equals the square of the pooled two-proportion z statistic, and the p-values match the two-sided z test. Chi-square cannot test a one-sided alternative; use z for that.

Conditions: the data must be counts of individuals, each individual in exactly one cell, from random samples or random assignment, and all expected counts should be at least 5. Percentages, means, or multiple selections per person break the test. When expected counts are small, merge sensible categories or use an exact test. Never double the data or delete awkward rows. Remember also that χ² grows with sample size when proportions are fixed, so a huge sample can make a weak association highly significant.

After a significant result, describe the association. Standardized residuals (O − E)/√E show which cells sit far above or below expectation; values beyond about ±2 stand out. The cell contributions tell the same story in squared form. Effect size measures like Cramér's V = √(χ²/(n·min(r − 1, c − 1))) put strength on a 0 to 1 scale. Finally, interpret carefully: a test of independence on observational data shows association, not causation, and a lurking variable can even reverse an association when tables are combined (Simpson's paradox). Failing to reject H₀ does not prove independence.

Key ideas

Formulas and rules

χ² = Σ (O − E)²/E
GOF: E = n·pᵢ, df = k − 1 − (parameters estimated)
Two-way: E = (row total)(column total)/n, df = (r − 1)(c − 1)
Standardized residual = (O − E)/√E
2 × 2 table: χ² = z² (pooled two-proportion z)
Cramér's V = √(χ²/(n·min(r − 1, c − 1)))

Common mistakes

Before the test, make sure you can

Words to know

Chi-square statistic
Σ(O − E)²/E, a measure of how far observed counts are from expected counts.
Chi-square distribution
A right-skewed distribution of nonnegative values with mean equal to its df.
Goodness-of-fit test
Tests whether one categorical variable follows a hypothesized distribution.
Test of independence
Tests whether two categorical variables are associated in one population, from one sample.
Test of homogeneity
Tests whether several populations share the same distribution of a categorical variable, from separate samples.
Expected count
The count predicted by H₀; n·p for GOF or row × column / total for two-way tables.
Two-way table
A table of counts cross-classifying individuals by two categorical variables.
Degrees of freedom (two-way)
(r − 1)(c − 1), the number of cells free to vary given the margins.
Cell contribution
(O − E)²/E for one cell; large contributions show where the data depart from H₀.
Standardized residual
(O − E)/√E; values beyond about ±2 mark cells that differ notably from expectation.
Cramér's V
An effect-size measure for two-way tables, between 0 (none) and 1 (perfect association).
Simpson's paradox
A reversal of an association when groups are combined, caused by a lurking variable.
Fisher's exact test
An exact alternative for small two-way tables where expected counts are too low.
Estimated parameter
A model value computed from the data, which costs one degree of freedom in a GOF test.

Sample practice questions

30 more questions like these, from level 1 to 5, are in the practice set.

Question 1 (level 1)

The chi-square statistic Σ(O − E)²/E measures:

  1. The proportion of cells with counts below 5
  2. How far observed counts are from the counts expected under H₀
  3. How far sample means are from a hypothesized mean
  4. The correlation between two categorical variables in a table
Show the answer and steps

Answer: B) How far observed counts are from the counts expected under H₀

  1. O is each observed count and E the count expected if H₀ were true.
  2. Each squared gap is scaled by E and the pieces are summed.
  3. Large values signal that the data do not fit H₀.
Question 2 (level 1)

A chi-square goodness-of-fit test with k categories (no parameters estimated) has how many degrees of freedom?

  1. k
  2. k − 1
  3. k − 2
  4. (k − 1)²
Show the answer and steps

Answer: B) k − 1

  1. The k counts must add up to n, so one count is determined by the others.
  2. That leaves k − 1 free counts.
  3. Each parameter estimated from the data would subtract one more.
Question 3 (level 3)

A die is rolled 120 times, giving faces 1 to 6 counts of 15, 25, 18, 22, 12 and 28. For a goodness-of-fit test of fairness, what are χ² and the p-value?

  1. χ² = 9.30, p ≈ 0.026
  2. χ² = 46.5, p < 0.001
  3. χ² = 9.30, p ≈ 0.098
  4. χ² = 1.55, p ≈ 0.91
Show the answer and steps

Answer: C) χ² = 9.30, p ≈ 0.098

  1. Each expected count is 120/6 = 20.
  2. Contributions: 25/20 + 25/20 + 4/20 + 4/20 + 64/20 + 64/20 = 186/20 = 9.30.
  3. With 5 df, p ≈ 0.098; 0.026 uses 3 df, and 46.5 forgets to divide by E.