LightMySky

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.

No account needed. Progress saves in this browser.

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.

Try it together

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.

Good to know

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.

More to read

11.2 Goodness-of-Fit Test

A goodness of fit test asks whether observed counts match a claimed distribution. For each category, compare the observed count O with the expected count E under the claim, then add up (O minus E) squared over E across all categories. Large totals signal a poor fit.

Degrees of freedom equal the number of categories minus 1, because the total count fixes one of them. The test needs expected counts of at least 5 in each cell. When that rule fails, small cells should be combined before trusting the result.

11.3 Test of Independence

A test of independence works on a contingency table with rows for one variable and columns for another. Under the null claim the two variables are unrelated, so each cell expects its row total times its column total divided by the grand total. The same sum of (O minus E) squared over E then measures how far the table strays from independence.

Degrees of freedom are (rows minus 1) times (columns minus 1). As usual, every expected count should reach at least 5. Rejecting the null means spotting an association, though it never proves that one variable causes the other.

11.4 Test for Homogeneity

A homogeneity test compares several populations to see whether they share the same distribution of a categorical trait. The table layout looks like the independence test, but the design differs: separate samples are drawn from each population, one per row or column. Expected counts and the statistic are computed the same way.

Because the arithmetic matches, students often mix the two tests up. The question wording settles it: one sample sorted two ways means independence, while several samples compared on one trait means homogeneity. State the design before computing so the conclusion answers the right question.

Explore more

2 · Watch

Take it off screen

Print a worksheetA4 with an answer key page for grown-ups. No screen, no internet.

Where it sits

Where this leads

Jobs that lean on this skill. Follow one to see everything it is built on.

Then practise

14 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.

Spotted a problem on this page? Tell us
Chi-Square Tests for Categorical Data · Mathematics, ages 21 to 22 · LightMySky