inferential statistics
Chi-Square Test
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
For k categories with observed counts Oᵢ and expected counts Eᵢ under H₀:
Worked Examples
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.
Sum the contributions.
Answer: χ² = 1.0, with df = 5 (not extreme — consistent with a fair die).
Practice Problems
A survey expects 4 categories each with expected count 25 (total n=100). Observed counts are 20, 30, 25, 25. Compute χ².
For a goodness-of-fit test with 6 categories, how many degrees of freedom does the chi-square statistic have?
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
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
- WebsiteWikipedia — Chi-squared test
Mathematics