Mathematics.

inferential statistics

Chi-Square Test

Statistics30 minDifficulty4 out of 10

You should know: hypothesis testing

Overview

The chi-square test is a hypothesis test used with categorical data to compare observed frequencies against frequencies expected under some null hypothesis. Its two most common forms are the chi-square goodness-of-fit test, which checks whether observed category counts match a hypothesized distribution, and the chi-square test of independence, which checks whether two categorical variables are associated (e.g., in a contingency table). The test statistic sums the squared difference between observed and expected counts, scaled by the expected counts, and compares the result to a chi-square distribution with an appropriate number of degrees of freedom. Larger discrepancies between observed and expected counts produce larger test statistics and smaller p-values, indicating stronger evidence against the null hypothesis.

Intuition

The chi-square statistic quantifies how far observed data deviates from what you'd expect if the null hypothesis were exactly true. Each category contributes (observed − expected)² / expected — squaring makes both over- and under-counts contribute positively, and dividing by the expected count normalizes the deviation relative to the size expected in that category (a discrepancy of 5 matters more in a category expected to have 10 than in one expected to have 1000). Summing across all categories gives an overall measure of mismatch, which is then compared to the chi-square distribution to judge whether the mismatch is more than chance would produce.

Formal Definition

Definition

For k categories with observed counts Oᵢ and expected counts Eᵢ under H₀:

χ2=i=1k(OiEi)2Ei\chi^2 = \sum_{i=1}^{k} \frac{(O_i - E_i)^2}{E_i}
Chi-square test statistic
χ2χdf2,df=k1 (goodness-of-fit)\chi^2 \sim \chi^2_{df}, \quad df = k - 1 \text{ (goodness-of-fit)}
Degrees of freedom, goodness-of-fit
df=(r1)(c1) (test of independence, r rows, c columns)df = (r-1)(c-1) \text{ (test of independence, } r \text{ rows, } c \text{ columns)}
Degrees of freedom, independence test

Worked Examples

  1. Compute (O-E)²/E for each face: face1 (8-10)²/10=0.4, face2 (12-10)²/10=0.4, face3 (9-10)²/10=0.1, face4 (11-10)²/10=0.1, face5 (10-10)²/10=0, face6 (10-10)²/10=0.

    χ2=0.4+0.4+0.1+0.1+0+0\chi^2 = 0.4+0.4+0.1+0.1+0+0
  2. Sum the contributions.

    χ2=1.0\chi^2 = 1.0

Answer: χ² = 1.0, with df = 5 (not extreme — consistent with a fair die).

Practice Problems

Difficulty 3/10

A survey expects 4 categories each with expected count 25 (total n=100). Observed counts are 20, 30, 25, 25. Compute χ².

Difficulty 4/10

For a goodness-of-fit test with 6 categories, how many degrees of freedom does the chi-square statistic have?

Difficulty 5/10

A researcher wants to test whether smoking status (smoker/non-smoker) is associated with disease status (yes/no) using a 2×2 contingency table. What test should be used, and what are its degrees of freedom?

Quiz

The chi-square goodness-of-fit test is used to:
For an r×c contingency table, the degrees of freedom for a chi-square test of independence is:
A larger chi-square statistic indicates:

Summary

  • The chi-square test compares observed categorical frequencies to expected frequencies under a null hypothesis.
  • The test statistic is χ² = Σ(O-E)²/E, compared against a chi-square distribution with appropriate degrees of freedom.
  • Common forms are the goodness-of-fit test (one categorical variable) and the test of independence (association between two categorical variables).

References