Chi-Square Tests for Categorical Data
Compare observed counts with the counts a model predicts. The same statistic serves goodness of fit, independence and homogeneity, with the degrees of freedom telling them apart.
What a learner can do afterwards
- Compute expected counts and the statistic for a contingency table
- State the degrees of freedom for each of the three tests
- Check the expected-count condition before trusting the result
1 · Read
A goodness of fit test asks whether observed counts match a claimed distribution. For each category you compare the observed count with the expected count under the claim and add up the squared gap divided by the expected count across all categories. Large totals signal a poor fit. The degrees of freedom are the number of categories minus 1, and every expected count should reach at least 5.
A test of independence works on a table with rows for one variable and columns for the other. When the variables are unrelated, each cell expects its row total times its column total divided by the grand total, and the same sum of squared gaps over expected measures the distance from independence. The degrees of freedom are rows minus 1 times columns minus 1, and the same expected count rule of at least 5 applies.
A cell sits in a row totalling 30 and a column totalling 40 with 120 observations overall. Its expected count is 30 times 40 divided by 120, which is 10. A table with 3 rows and 4 columns uses 2 times 3, which is 6 degrees of freedom.
Homogeneity looks numerically like independence but starts from several separate samples compared on one trait, while independence sorts one sample two ways. Read the design first: one sample sorted twice means independence, and several samples compared means homogeneity. Rejecting either test shows an association but never proves cause.
Expected counts set the target, the statistic measures the miss, and the design names the question.
2 · Watch
Take it off screen
Where it sits
Where this leads
Jobs that lean on this skill. Follow one to see everything it is built on.
8 questions wait behind this lesson, each with its answer explained. Every answer feeds the sky: stars light as they are learned, and dim when it is time to come back.