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
colourredorangeyellowgreenblueobserved6129442145claimed30%20%20%15%15%

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.

n = 200k = 5
Next problem →
Practise Chi-square tests for freePractise Chi-square tests now5 free problems every day. No card needed.

What you practise

  1. Easygoodness of fit
  2. Mediumtest of independence
  3. Hardcritical value decision

Key formulas

Test statistic
χ² = Σ(O − E)²/E
Goodness of fit
E = n·p, df = k − 1 − (estimated parameters)
Independence
E = row total × column total / grand total, df = (r − 1)(c − 1)
Critical values (α = 0.05)
df 1: 3.841, 2: 5.991, 3: 7.815, 4: 9.488
Decision
reject H0 if χ² > χ²crit

Learn Chi-square tests from scratch

Before this: Hypothesis tests & confidence intervals

1What a chi-square test does

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. 1/6
  2. 120
  3. 20
  4. 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.

For the die: (8 − 10)²/10 + (12 − 10)²/10 + … + (14 − 10)²/10 = (4 + 4 + 1 + 1 + 16 + 16)/10 = 4.2.

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 χ²?
  1. 0.4
  2. 1.6
  3. 16
  4. 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?
  1. 10
  2. 1200
  3. 3
  4. 70

Answer: 10. E = 40 · 30 / 120 = 1200/120 = 10. 1200 forgets to divide by the grand total.

4The method step by step

  1. State H₀: the claimed proportions are right (goodness of fit), or the variables are independent.
  2. Compute every expected count: E = n · p, or row total × column total / grand total.
  3. For each cell, compute (O − E)²/E. Add them all to get χ².
  4. Find df: k − 1 for goodness of fit, (r − 1)(c − 1) for independence.
  5. Look up the critical value for that df at α = 0.05.
  6. 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

12ΣABΣ56641205446100110110220

Row totals: 120 and 100. Column totals: 110 and 110. Grand total: 220.

2

Expected counts

EA1 = 120 · 110 / 220 = 60, EA2 = 60
EB1 = 100 · 110 / 220 = 50, EB2 = 50
12ΣABΣ56(60)64(60)12054(50)46(50)100110110220
3

The statistic

χ² = (56 − 60)²/60 + (64 − 60)²/60 + (54 − 50)²/50 + (46 − 50)²/50
χ² = 0.267 + 0.267 + 0.32 + 0.32 = 1.173
4

Degrees of freedom and critical value

df = (2 − 1)(2 − 1) = 1, χ²crit = 3.841
5

Decide

3.8415%1.17χ²

1.173 is smaller than 3.841, so χ² is not in the rejection region. Do not reject H₀.

Answer

χ² ≈ 1.17 < 3.841: no significant evidence that improvement depends on the treatment.

6Common mistakes

  • Using percentages or proportions instead of counts. χ² only works with counts.
  • Dividing by O instead of by E.
  • Including the totals row or column in the sum.
  • Using the wrong df: for a table it is (r − 1)(c − 1), not the number of cells minus one.
  • Rejecting H₀ when χ² is smaller than the critical value. Only a large χ² is evidence against H₀.
Self-check A test of independence uses a table with 3 rows and 4 columns (not counting totals). How many degrees of freedom does it have?
  1. 11
  2. 12
  3. 5
  4. 6

Answer: 6. df = (3 − 1)(4 − 1) = 2 · 3 = 6. 11 is the number of cells minus one, which is the goodness-of-fit rule applied to a table by mistake.

7How exam questions look

  • Easy: goodness of fit. Counts of die faces or sweet colours against claimed proportions; compute χ².
  • Medium: the test of independence. Compute the expected counts from the totals, then χ², without a continuity correction.
  • Hard: the critical value decision. Find df and the critical value χ²crit at α = 0.05 from the table.

A quick check: χ² is never negative, and it is 0 only when every observed count equals its expected count.

Learn it step by step in the appLearn it step by step in the app

Worked examples

Example 1Easy
face123456observed534862505433

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
  1. Expected counts under H₀: E = n·p for each category.
  2. E = 50, 50, 50, 50, 50, 50.
  3. 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 α.

Expected counts

E = 300·p = 50, 50, 50, 50, 50, 50

Chi-square statistic

χ² = (53 − 50)²/50 + (48 − 50)²/50 + (62 − 50)²/50 + (50 − 50)²/50 + (54 − 50)²/50 + (33 − 50)²/50
χ² = 9.24

Answer

χ² = 9.24

df = 5. At α = 0.05 the critical value is 11.070, so H₀ is not rejected.

Example 2Medium
coughno coughTotalsmokers334780non-smokers3961100Total72108180

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
  1. Expected count of each cell: E = row total × column total / grand total.
  2. E = 32, 48 | 40, 60.
  3. 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 α.

Expected counts

smokers: 80·72/180 = 32, 80·108/180 = 48
non-smokers: 100·72/180 = 40, 100·108/180 = 60

Chi-square statistic

χ² = (33 − 32)²/32 + (47 − 48)²/48 + (39 − 40)²/40 + (61 − 60)²/60
χ² = 0.09375

Answer

χ² = 0.09375

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
  1. Degrees of freedom count how many cells can vary freely once the totals (and any estimated parameters) are fixed.
  2. Goodness of fit: k − 1, minus one for each estimated parameter.
  3. 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.

Topics before and after this one

Learn first

Calculators

Courses with this topic

More topics in Mathematics & statistics

Printable worksheet

Practise Chi-square tests for freePractise Chi-square tests now5 free problems every day. No card needed.