Chi-square test
By Jude Wallis · Published
A chi-square test compares observed counts of categorical data to the counts expected under a hypothesis, gauging how far the data stray from that model.
A chi-square test asks whether a table of counts sits further from a model than sampling variability explains. Every version computes across the cells, where is an observed count and the expected count under the null. Squaring throws away the direction of each gap, so every discrepancy pushes the statistic up instead of cancelling another, and all the evidence against the null lives in the upper tail of the chi-square curve.
Two schools are surveyed about biking to school: School A has 45 bikers out of 100, School B 45 out of 140. The expected counts from the margins are 37.5 and 62.5 in the first row, 52.5 and 87.5 in the second, so the four terms are 1.5, 0.9, 1.0714, and 0.6429. That gives on degree of freedom, and a p-value of 0.0425. At that is convincing evidence the two schools differ in their biking rates.
The error that ruins the test: "School A bikes at 45 percent and School B at 32.1 percent, so those go in the formula." Percentages are not counts, and scales with how much data stands behind it. Double both schools while holding those two percentages fixed and the statistic doubles to 8.2286 with a p-value of 0.0041. Raw counts carry the sample size; percentages discard it.
Three tests share the formula and differ in where comes from and how the degrees of freedom are counted. Homogeneity compares separate samples on one categorical variable, which is the table above. Independence takes one sample and cross-classifies it two ways. Both read off the margins and use degrees of freedom. Goodness of fit checks one variable against claimed proportions using .
Homogeneity and independence are AP Statistics topics 3.14 and 3.15. Goodness of fit was removed from the course for Fall 2026, so it is not examinable, though it stays standard in a college introductory course.
Where this comes up
- Chi-square test explained: 3 tests, one formulaGuide
- AP Stats 3.14: Setting Up a Chi-Square TestAP topic
- AP Stats 3.15: Carrying Out a Chi-Square TestAP topic
- Is chi-square goodness of fit on the AP exam?Guide
- Chi-square practice problemsPractice
- AP Statistics Project Ideas for High SchoolGuide
- Chi-square two-way table practice problemsPractice
- Which statistical test should I use? A decision guideGuide
23 pages on the site use this term.
More hypothesis testing terms, or browse the full statistics glossary.