Chi-square tests: practice problems with step-by-step solutions
Also called: χ² test · goodness of fit · test of independence
Free Chi-square tests practice problems with diagrams, hints and full worked solutions. New values every time, at three levels: goodness of fit, test of independence, critical value decision.
Free practice problemEasy
A sweet manufacturer claims the colour proportions shown in the table. A random sample of 200 sweets gives the observed counts. Compute the chi-square goodness-of-fit statistic χ² for H₀: the claimed proportions are correct.
A chi-square test (χ², “kai square”) compares counts. It asks whether the counts you observe differ from the counts you expect by more than chance.
Example: you roll a die 60 times. If it is fair, each face should come up about 60 · 1/6 = 10 times. Those are the expected counts E.
You observe 8, 12, 9, 11, 6 and 14. These are the observed counts O. They are never exactly 10, even for a fair die. The question is whether they are too far off.
As in every hypothesis test, H₀ says nothing special is going on: the die is fair, or two variables are independent.
Self-check A die is rolled 120 times to test whether it is fair. What is the expected count for each face?
1/6
120
20
6
Answer: 20. E = n · p = 120 · 1/6 = 20. The probability 1/6 is not a count; you must multiply it by the number of rolls.
2The test statistic
For each category, take the difference O − E, square it, and divide by E. Then add over all categories:
χ² = Σ (O − E)² / E
Squaring makes every term positive. Dividing by E makes a difference of 4 count more when only 10 were expected than when 1000 were expected.
The degrees of freedom for this goodness-of-fit test are df = k − 1, where k is the number of categories. Six faces give df = 5.
A large χ² means the data fit H₀ badly. Reject H₀ if χ² is larger than the critical value from the table. At α = 0.05:
df 1: 3.841, df 2: 5.991, df 3: 7.815
df 4: 9.488, df 5: 11.070, df 6: 12.592
For the die, 4.2 is below 11.070, so there is no evidence that it is unfair.
Self-check One category has O = 14 and E = 10. What does it add to χ²?
0.4
1.6
16
4
Answer: 1.6. (14 − 10)²/10 = 16/10 = 1.6. Forgetting to square gives 0.4, and forgetting to divide by E gives 16.
3The test of independence
A contingency table counts cases by two variables at once, such as treatment (rows) and result (columns). H₀: the two variables are independent.
If they are independent, the expected count in each cell follows from the totals:
E = row total × column total / grand total
Then χ² is computed with the same formula as before, over every cell of the table, without the totals.
df = (r − 1)(c − 1)
Here r is the number of rows and c the number of columns, not counting the totals. A 2×2 table has df = 1.
Self-check In a table with grand total 120, a cell has row total 40 and column total 30. What is its expected count?
10
1200
3
70
Answer: 10. E = 40 · 30 / 120 = 1200/120 = 10. 1200 forgets to divide by the grand total.
4The method step by step
State H₀: the claimed proportions are right (goodness of fit), or the variables are independent.
Compute every expected count: E = n · p, or row total × column total / grand total.
For each cell, compute (O − E)²/E. Add them all to get χ².
Find df: k − 1 for goodness of fit, (r − 1)(c − 1) for independence.
Look up the critical value for that df at α = 0.05.
Reject H₀ if χ² is larger than the critical value. State the conclusion in words.
Check: the expected counts in each row and column add up to the same totals as the observed counts.
5A worked example
Follow every step. Try to predict the next one before you open it.
Worked example
In a trial, 120 patients get a new drug (row A) and 100 get a placebo (row B). Column 1 counts the patients who improved, column 2 those who did not. Test at α = 0.05 whether the result is independent of the treatment.
1
Read the table
Row totals: 120 and 100. Column totals: 110 and 110. Grand total: 220.
A die is rolled 300 times to test whether it is fair. The counts of each face are shown. Compute the chi-square goodness-of-fit statistic χ² for H₀: each face has probability 1/6.
n = 300k = 6
Find χ²
Show hints
Expected counts under H₀: E = n·p for each category.
E = 50, 50, 50, 50, 50, 50.
Add up (O − E)²/E over all categories.
Show the answer and the step-by-step solution
Chi-square tests: compare observed counts O with the counts E expected under H₀ using χ² = Σ(O − E)²/E. Goodness of fit: E = n·p for each category, df = k − 1 (minus one more for each parameter estimated from the data). Independence in an r × c table: E = row total × column total / grand total, df = (r − 1)(c − 1). Reject H₀ when χ² exceeds the critical value for the chosen α.
df = 5. At α = 0.05 the critical value is 11.070, so H₀ is not rejected.
Example 2Medium
The contingency table shows observed counts. Compute the chi-square statistic χ² for the test of independence between the row and column variables. Do not use a continuity correction.
N = 1802 × 2
Find χ²
Show hints
Expected count of each cell: E = row total × column total / grand total.
E = 32, 48 | 40, 60.
Add up (O − E)²/E over all 4 cells.
Show the answer and the step-by-step solution
Chi-square tests: compare observed counts O with the counts E expected under H₀ using χ² = Σ(O − E)²/E. Goodness of fit: E = n·p for each category, df = k − 1 (minus one more for each parameter estimated from the data). Independence in an r × c table: E = row total × column total / grand total, df = (r − 1)(c − 1). Reject H₀ when χ² exceeds the critical value for the chosen α.
df = 1. At α = 0.05 the critical value is 3.841, so H₀ (independence) is not rejected.
Example 3Hard
A chi-square test of independence is carried out on a contingency table with 2 rows and 6 columns (not counting the totals). How many degrees of freedom df does the test have?
2 × 6
Find df
Show hints
Degrees of freedom count how many cells can vary freely once the totals (and any estimated parameters) are fixed.
Goodness of fit: k − 1, minus one for each estimated parameter.
Independence: (r − 1)(c − 1).
Show the answer and the step-by-step solution
Chi-square tests: compare observed counts O with the counts E expected under H₀ using χ² = Σ(O − E)²/E. Goodness of fit: E = n·p for each category, df = k − 1 (minus one more for each parameter estimated from the data). Independence in an r × c table: E = row total × column total / grand total, df = (r − 1)(c − 1). Reject H₀ when χ² exceeds the critical value for the chosen α.
Degrees of freedom
df = (2 − 1)·(6 − 1) = 5
Answer
df = 5
Questions and answers
What is Chi-square tests?
A chi-square test (χ², “kai square”) compares counts. It asks whether the counts you observe differ from the counts you expect by more than chance.
Example: you roll a die 60 times. If it is fair, each face should come up about 60 · 1/6 = 10 times. Those are the expected counts E.
How do I solve Chi-square tests problems step by step?
Chi-square tests: compare observed counts O with the counts E expected under H₀ using χ² = Σ(O − E)²/E. Goodness of fit: E = n·p for each category, df = k − 1 (minus one more for each parameter estimated from the data). Independence in an r × c table: E = row total × column total / grand total, df = (r − 1)(c − 1). Reject H₀ when χ² exceeds the critical value for the chosen α.
What are common mistakes in Chi-square tests?
Divide each squared difference by the expected count E, not by the observed count O.
Divide each squared difference by its own expected count E before adding, not the total by n.
Expected counts come from the margins, not from spreading the total evenly: E = row total × column total / grand total.
What do the Chi-square tests exercises cover?
Easy: goodness of fit
Medium: test of independence
Hard: critical value decision
Every problem has new values, so you learn the method instead of an answer. Stuck? Open a small hint first, and the full explanation only when you need it.
How practising works
Every problem has new values, so you learn the method instead of an answer.
Stuck? Open a small hint first, and the full explanation only when you need it.
Your progress, mistakes and saved problems are kept, so you can review before the exam.