Carrying Out a Chi-Square Test for Homogeneity or Independence
Turn a two-way count table into an evidence-based conclusion. Calculate expected counts, build the chi-square statistic, find its right-tail -value and explain what the result means for the populations.
By the end of this lesson, you should be able to:
- Calculate every expected count from the marginal totals.
- Calculate and interpret each cell’s contribution to .
- Find the correct degrees of freedom and right-tail -value.
- Interpret the -value assuming the contextual null hypothesis is true.
- Compare the -value with and write an appropriate population conclusion.
- Explain why statistical significance, practical importance and causation are different claims.
Before you start: Review Topic 3.14: choosing the test, writing hypotheses and checking conditions. You should recognize row totals, column totals and the grand total of a two-way table.
First time learning this? Follow the three-school preference study from its counts to its conclusion, then try the six worked examples.
Here to revise? Review the calculation checklist, then attempt the ten practice questions before opening hints and solutions.
The concept in 60 seconds
A chi-square test compares observed counts with the counts predicted by the null hypothesis. A small mismatch is ordinary sample variation. A sufficiently large overall mismatch provides evidence against the null model.
Two designs use the same calculation. Homogeneity compares categorical response distribution across independently sampled populations or randomly assigned treatments. Independence investigates association between categorical variables in sampled population. Your design determines which name and conclusion fit.
Predict each cell from the row total, column total and grand total, after justifying the design.
Square each difference, divide by and add every interior-cell contribution.
Use the chi-square curve with . Find the area from the statistic to the right.
Compare with the preselected and describe evidence about the populations or association.
A calculation is part of the inference. Keep the populations, hypothesis and design attached to every step.
The key chain: observed counts → expected counts under → nonnegative cell contributions → statistic → a right-tail -value → a contextual decision.
The test uses counts of individuals, rather than percentages alone. Each individual contributes to row-and-column combination. All studies on this page are fictional teaching examples; the numerical results are calculated from the stated data.
Quick check: do homogeneity and independence use different statistic formulas?
No. Both use with . Their study designs, hypotheses and population conclusions differ.
Follow the three-school preference study
Researchers select independent SRSs without replacement from Schools A, B and C. The samples contain students, respectively, from populations of students. Each student chooses exactly preferred notes format: digital only, printed only or mixed.
The investigative question is: Is the distribution of preferred notes format the same across the school populations? Use a chi-square test for homogeneity. Choose before evaluating the result.
| School population | Digital only | Printed only | Mixed | Total |
|---|---|---|---|---|
| School A | ||||
| School B | ||||
| School C | ||||
| Total |
: The distribution of preferred notes format is the same among all students at Schools A, B and C.
: Those population distributions are not all the same; at least differs.
The null does not require of students to prefer each category. It requires a common distribution across schools, whose category shares may be unequal. Unequal sample sizes also mean that equal population distributions do not predict equal raw counts.
Verify the setup before calculating a -value
- Randomization and independent observations: Independent SRSs are specified, and each student contributes response. The samples do not consist of the same students measured repeatedly.
- condition for each sampled population: ; ; .
- Expected counts: The next section calculates every interior expectation. The minimum is , so all exceed .
Use the same criterion as Topic 3.14, following the Fall 2026 AP course framework. Some other texts use ; an exact does not pass the strict wording used here. The sampling check is not required merely for random assignment. A separate finite-population sampling stage can still require its own check.
Quick check: may we combine all school populations for check?
No. These samples were separately selected from populations. Check each sample against its own population. A large combined population can hide an overly large sampling fraction in school.
Calculate every expected cell count
Use the table’s margins to calculate the expected count in each interior cell:
For School A’s digital-only cell, the row total is , the column total is and the grand total is :
Another way to see this: the pooled digital proportion is . Under the common-distribution null, of a sample of is an expected digital preferences. The combined printed and mixed proportions are and .
| School population | Digital only | Printed only | Mixed | Total |
|---|---|---|---|---|
| School A | ||||
| School B | ||||
| School C | ||||
| Total |
The expected table preserves the observed row totals, column totals and grand total. For example, School A’s expectations sum to . The digital column sums to . These checks can reveal an arithmetic or data-entry error.
What to remember about
- An observed count is what happened; an expected count is predicted by the null model using the margins.
- Expected counts can be fractional. They describe model-based counts, so they need not be whole numbers.
- Keep full precision for the statistic. Rounding too early can change the final -value.
- Check every interior expected cell. The margins are totals, rather than additional response categories.
For an independence test: the same formula predicts a cell count when the categorical variables are independent. The table arithmetic stays the same, while the null claim refers to the variables in population.
Quick check: why is School B’s expected digital count rather than ?
B has a sample of , compared with A’s . Applying the common digital share gives . A homogeneity null predicts the same proportions, rather than the same counts.
Build the chi-square statistic
The Pearson chi-square statistic adds contribution from every interior cell:
Read the formula as: subtract expected from observed, square that difference, divide by the expected count, and add the results. The sum uses all school-study cells.
. A positive difference is an observed excess in this sample cell.
. An equally large shortage would have the same square.
. Add this to the other contributions for the school statistic.
A contribution measures this cell’s squared, scaled mismatch with its fitted null expectation. It is not a -value or an independent test decision.
For A’s digital cell, and , so the contribution is . For A’s printed cell, and , giving .
| Cell | Observed | Expected | Contribution |
|---|---|---|---|
| A: Digital only | |||
| A: Printed only | |||
| A: Mixed | |||
| B: Digital only | |||
| B: Printed only | |||
| B: Mixed | |||
| C: Digital only | |||
| C: Printed only | |||
| C: Mixed |
, using the unrounded cell contributions.
Why square and divide?
Squaring prevents positive and negative differences from cancelling. Under the margins are preserved, so signed differences can sum to even when many cells differ. Both an excess and a shortage can add evidence against the null.
Dividing by adjusts for the count scale. A difference of with contributes ; the same difference with contributes . Comparing only the raw differences misses this scaling.