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
- χ² = Σ(O − E)²/E compares observed counts with counts expected under H₀.
- Chi-square tests are right-tailed because any departure from H₀ increases χ².
- GOF tests use k − 1 df, minus one for each estimated parameter.
- Two-way tables use E = row × column / total and df = (r − 1)(c − 1).
- Independence and homogeneity tests share arithmetic but differ in design and hypotheses.
- All expected counts should be at least 5, and each individual counts in only one cell.
- Standardized residuals and Cramér's V describe where and how strong an association is.
Formulas and rules
Common mistakes
- Checking observed counts instead of expected counts against the 5 rule.
- Using rc − 1 or k as the degrees of freedom.
- Running chi-square on percentages or on data where people fall in several cells.
- Interpreting a significant association in observational data as causation.
- Concluding the variables are independent because the p-value is large.
Before the test, make sure you can
- Choose among goodness-of-fit, independence and homogeneity tests from a study description.
- Calculate expected counts for one-way and two-way tables.
- Compute χ², its degrees of freedom and the p-value.
- Check the expected-count and independence conditions, and fix small-count problems properly.
- Use cell contributions or standardized residuals to describe an association.
- Relate a 2 × 2 chi-square test to the two-proportion z test.
- State conclusions in context without claiming causation or proving independence.
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.
The chi-square statistic Σ(O − E)²/E measures:
- The proportion of cells with counts below 5
- How far observed counts are from the counts expected under H₀
- How far sample means are from a hypothesized mean
- 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₀
- O is each observed count and E the count expected if H₀ were true.
- Each squared gap is scaled by E and the pieces are summed.
- Large values signal that the data do not fit H₀.
A chi-square goodness-of-fit test with k categories (no parameters estimated) has how many degrees of freedom?
- k
- k − 1
- k − 2
- (k − 1)²
Show the answer and steps
Answer: B) k − 1
- The k counts must add up to n, so one count is determined by the others.
- That leaves k − 1 free counts.
- Each parameter estimated from the data would subtract one more.
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?
- χ² = 9.30, p ≈ 0.026
- χ² = 46.5, p < 0.001
- χ² = 9.30, p ≈ 0.098
- χ² = 1.55, p ≈ 0.91
Show the answer and steps
Answer: C) χ² = 9.30, p ≈ 0.098
- Each expected count is 120/6 = 20.
- Contributions: 25/20 + 25/20 + 4/20 + 4/20 + 64/20 + 64/20 = 186/20 = 9.30.
- With 5 df, p ≈ 0.098; 0.026 uses 3 df, and 46.5 forgets to divide by E.