Chi-square test calculator: 2x2 table and goodness-of-fit
By Jude Wallis · Published
A chi-square test calculator finds each cell's expected count as (row total times column total) / table total, then computes chi^2 = sum of (observed - expected)^2 / expected. For observed 25, 15, 15, 45 the expected counts are 16, 24, 24, 36, so chi^2 = 14.0625 with df = 1.
test for independence / homogeneity (df = 1)
chi-square = 10.5263, p = 0.0012
Smallest expected count: 23.75 (all at least 5, condition met).
Steps
- 1.row totals: 70, 50; column totals: 63, 57; grand total: 120
- 2.expected count = (row total x column total) / grand total for every cell
- 3.expected counts: 36.75, 33.25 | 26.25, 23.75
- 4.chi-square = sum of (observed - expected)² / expected = 10.5263
- 5.df = (rows - 1)(columns - 1) = 1; right-tail p-value = 0.0012
AP Statistics: Unit 3 (topics 3.14 Setting Up a Chi-Square Test for Homogeneity or Independence, 3.15 Carrying Out a Chi-Square Test for Homogeneity or Independence). In the Fall 2026 AP Statistics course, chi-square tests for homogeneity and independence are Unit 3 topics 3.14 and 3.15, while the chi-square goodness-of-fit test was removed from the AP exam and now appears only in college introductory statistics.
What a chi-square test measures
A chi-square test compares the counts you actually observed in a table of categories against the counts you would expect if there were no relationship in the data. The chi-square statistic, written (chi-squared), measures how far the observed counts fall from the expected counts, relative to those expected counts. A larger means the observed table sits farther from what the null hypothesis predicts.
Two versions appear on the AP exam, and both run the same arithmetic on a two-way table. A test for independence asks whether two categorical variables are associated within a single population. A test for homogeneity asks whether the distribution of one categorical variable is the same across two or more populations or treatments.
Expected counts for a two-way table
The expected count for a cell is what you would predict if the row variable and the column variable were unrelated. For each cell, multiply its row total by its column total, then divide by the grand total:
Run this for every cell before you compute anything else. Expected counts do not have to be whole numbers, and the expected counts in any row still add up to that row's observed total.
The chi-square statistic and degrees of freedom
Once you have every expected count, apply the formula from the AP formula sheet:
Compute one term per cell, where Observed is the count you recorded and Expected is the count you predicted, then add the terms. Squaring each difference makes every term nonnegative, and dividing by the expected count scales each gap by how large it was supposed to be.
For a two-way table, the degrees of freedom are
A 2 by 2 table therefore has . The chi-square distribution you compare against takes only positive values and is skewed right, with the skew easing as grows.
Conditions to check first
The AP course requires three conditions before you trust a chi-square test for independence or homogeneity:
- Randomization: the data come from a random sample for a test of independence, or from independent random samples or a randomized experiment for a test of homogeneity.
- The 10% condition: when you sample without replacement, the sample size is no more than 10% of the population.
- Expected counts: every expected count is at least 5. Check the expected counts, not the observed counts.
If an expected count is less than 5, the chi-square approximation gets shaky, so combine categories or collect more data before running the test.
How to use the chi-square calculator
This chi-square calculator has two modes. For a two-way table, enter the observed counts row by row, and the tool fills in the row totals, column totals, expected counts, the statistic, the degrees of freedom, and the p-value.
- Type your observed counts into the grid, matching your rows and columns.
- Read the expected-count grid the tool returns, and confirm every expected count is at least 5.
- Use the reported , , and p-value to make a decision against your significance level.
Because it shows the expected grid and each cell's term, this chi-square calculator lets you retrace the arithmetic by hand. The second mode runs a goodness-of-fit test: enter observed counts and either equal or custom expected proportions for a single categorical variable.
Which version is on the AP exam
The chi-square tests for homogeneity and independence are on the Fall 2026 AP Statistics exam, in Unit 3 topics 3.14 and 3.15. The chi-square goodness-of-fit test was removed from the redesigned AP exam, though it stays standard in college introductory statistics, which is why this calculator still offers it.
For a goodness-of-fit test, the degrees of freedom equal the number of categories minus 1, and the expected count for each category is the total sample size times that category's hypothesized proportion. The statistic uses the same formula.
Chi-square test for independence on a 2 by 2 table
A random sample of 100 high school students is cross-classified by whether they play a school sport and whether they hold a part-time job. Test whether playing a sport and holding a job are independent. These are sample counts.
| Sport / Job | Job: yes | Job: no | Row total |
|---|---|---|---|
| Sport: yes | 25 | 15 | 40 |
| Sport: no | 15 | 45 | 60 |
| Column total | 40 | 60 | 100 |
State the hypotheses: the null hypothesis is that playing a sport and holding a job are independent for this population; the alternative hypothesis is that they are associated.
Find the totals: row totals 40 and 60, column totals 40 and 60, grand total 100.
Expected count, sport yes and job yes: .
Expected count, sport yes and job no: .
Expected count, sport no and job yes: .
Expected count, sport no and job no: .
Check the condition: every expected count (16, 24, 24, 36) is at least 5.
Cell term, sport yes and job yes: .
Cell term, sport yes and job no: .
Cell term, sport no and job yes: .
Cell term, sport no and job no: .
Add the terms: .
Degrees of freedom: .
From technology, a of 14.0625 with gives a p-value of about 0.0002.
with and a p-value near 0.0002. At any usual significance level you reject and conclude that playing a sport and holding a job are associated for this population.
Goodness-of-fit test for a fair die (college stats, not on the AP exam)
A six-sided die is rolled 60 times to test whether it is fair. This is a goodness-of-fit test, which is college statistics content and is not on the AP exam. These are sample counts.
| Face | 1 | 2 | 3 | 4 | 5 | 6 |
|---|---|---|---|---|---|---|
| Observed | 8 | 12 | 9 | 11 | 14 | 6 |
State the hypotheses: is that the die is fair, so each face has probability ; is that at least one face has a different probability.
Expected count per face: for all six faces, and each is at least 5.
Cell terms: , , , , , .
Add the terms: .
Degrees of freedom: number of categories minus 1, so .
From technology, a of 4.2 with gives a p-value of about 0.52.
with and a p-value near 0.52. The data do not provide strong enough evidence to conclude that the die is unfair.
Frequently asked questions
What is the difference between a chi-square test for independence and homogeneity?
A test for independence uses one random sample and asks whether two categorical variables are associated in that population. A test for homogeneity uses two or more samples or treatment groups and asks whether one categorical variable has the same distribution across them. The expected counts, statistic, and degrees of freedom are computed the same way; only the setup and conclusion differ.
What are the degrees of freedom for a chi-square test?
For a two-way table used in a test of independence or homogeneity, , so a 2 by 2 table has . For a goodness-of-fit test the degrees of freedom equal the number of categories minus 1.
What if an expected count is less than 5?
The expected counts condition is not met, so the chi-square approximation may be unreliable. Combine adjacent categories to raise the expected counts, or collect more data. Check the expected counts for this rule, not the observed counts.
Is the chi-square goodness-of-fit test on the AP Statistics exam?
No. The goodness-of-fit test was removed from the Fall 2026 redesigned AP Statistics course, which keeps only the chi-square tests for homogeneity and independence in Unit 3, topics 3.14 and 3.15. Goodness-of-fit is still standard in college introductory statistics, so this calculator includes it.