StatsDrillFree guides

Intro statistics · Counts in categories

Chi-square test practice problems

A chi-square test checks whether the counts you got are too far from the counts predicted by a stated model (the null hypothesis). Goodness of fit compares one variable with a claim. A test of independence asks whether two variables are related. The test statistic uses the same formula either way, and this page gives you 17 problems to practice them with instant feedback.

First, work out which test you have

To choose the test, ask two things: how many categorical variables are there, and how many samples were taken?

The three tests compared
CompareGoodness of fitTest of independenceTest of homogeneity
QuestionDo the counts match a claim?Are two variables related?Do the groups have the same distribution?
DataOne sample, one variableOne sample, two variablesSeparate samples, one variable
Looks likeA single row of countsA two-way tableA two-way table
H₀The stated shares are rightThe variables are independentThe distribution is the same in every group
Expected countn × claimed sharerow total × column total ÷ nrow total × column total ÷ n
Degrees of freedomk − 1(r − 1)(c − 1)(r − 1)(c − 1)

Swipe the table sideways to see all three tests.

Here, n is the sample size, k is the number of categories, r is the number of rows and c is the number of columns. The goodness-of-fit formula df = k − 1 assumes the claimed shares are fixed in advance, as they are throughout this guide. Fitting parameters from the same sample can reduce df further. For comparing means of numerical data, like hours or height, use the which statistical test chart instead.

The formula and the steps

Chi-square equals the sum of observed minus expected, squared, divided by expected, over all cells.

O is the count you observed and E is the count H₀ predicts. Each category or cell gets its own (O − E)²/E, and you add them all up. A statistic near 0 means the data sit close to H₀. A big one means they don’t.

  1. State H₀ and Hₐ in words. For these tests, H₀ says the claimed shares hold, the variables are independent, or the groups have the same distribution.
  2. Find every expected count and check the conditions below.
  3. Compute χ² by adding (O − E)²/E across every cell.
  4. Find df, then get a critical value or p-value from the right tail.
  5. Decide and say it in context. Reject H₀ if χ² is at or past the critical value, which is the same as p ≤ α.

Conditions to check

  • Counts: the data are counts of individuals, not percents or averages.
  • Sampling and independence: use a random sample or an appropriate randomized experiment. Observations must be independent, with each individual counted in exactly one cell. Repeated measurements or clusters need a different analysis. When sampling without replacement, the usual intro-course check is that the sample is no more than 10% of the population.
  • Big enough expected counts: this guide uses the conservative intro-course rule that every expected count must be at least 5. Follow your course’s rule if it differs. The rule is about E, not O; an observed count of 2 does not itself break it.
Chi-square curve for 3 degrees of freedomA curve that starts at zero, peaks near 1 and has a long tail to the right. The area to the right of 7.815 is shaded and marked as the 5 percent rejection region.04127.815Reject H₀top 5% of the curveFail to reject H₀
The chi-square curve with df = 3. When H₀ is true and the test conditions hold, χ² lands past 7.815 about 5% of the time. Bigger df shifts the curve to the right, so the critical value grows.
Chi-square critical values (right tail)
dfα = 0.10α = 0.05α = 0.01
12.7063.8416.635
24.6055.9919.210
36.2517.81511.345
47.7799.48813.277
59.23611.07015.086
610.64512.59216.812
712.01714.06718.475
813.36215.50720.090
914.68416.91921.666
1015.98718.30723.209

These critical values are rounded. If your statistic is very close to a cutoff, use a calculator p-value. On a TI-84 Plus with current software, the matching commands are in the STAT, TESTS menu: χ²GOF-Test and χ²-Test. Your exam may still ask for the expected counts, so learn the hand version too.

Worked examples

Example 1: Goodness of fit with equal shares

A tutoring center randomly samples 200 different students and records the weekday of each student’s most recent visit. Assume these observations are independent and the sample is under 10% of the center’s students. Are visits spread evenly across the weekdays? (Made-up data.) Test at α = 0.05.

Hypotheses. H₀: visits are spread evenly, so each day has a share of 1/5. Hₐ: at least one day’s share is different.

Expected. 200 × 1/5 = 40 for each day, so the 5 rule is fine.

Tutoring visits by weekday
DayOEO − E(O − E)²/E
Mon5240123.6
Tue444040.4
Wed3840−20.1
Thu3040−102.5
Fri3640−40.4
Total20020007.0

Decide. df = 5 − 1 = 4, so the critical value is 9.488. Since 7.0 is below that (p ≈ 0.136), fail to reject H₀.

In context. There isn’t enough evidence that visits differ by weekday. Monday looks busy, but a gap this size isn’t unusual for 200 visits. That doesn’t prove the visits are even.

Example 2: Genetics and Mendel’s 9:3:3:1 ratio

A genetics example starts with a predicted ratio. Mendel crossed pea plants that carried two traits and reported these real counts for 556 seeds. Do the data fit the predicted 9:3:3:1 ratio? Treat the seeds as independent outcomes for this textbook model; the ratio assumes independent assortment and complete dominance at both genes. Use α = 0.05.

Hypotheses. H₀: the seed types occur in a 9:3:3:1 ratio. Hₐ: they don’t.

Expected. The ratio adds to 16, so the shares are 9/16, 3/16, 3/16 and 1/16 of 556.

Pea seed counts against a 9:3:3:1 ratio
Seed typeOShareE(O − E)²/E
Round, yellow3159/16312.750.016
Wrinkled, yellow1013/16104.250.101
Round, green1083/16104.250.135
Wrinkled, green321/1634.750.218
Total55615560.470

Decide. df = 4 − 1 = 3, so the critical value is 7.815. Since 0.470 is far below that (p ≈ 0.93), fail to reject H₀.

In context. The counts are consistent with 9:3:3:1. A small χ² means little disagreement with this model. Biology problems often phrase this as “the deviation is due to chance,” but the careful version is that the data do not give enough evidence against the ratio.

Example 3: Test of independence with a 3 × 2 table

A random sample of 300 students reports their main study method and whether they passed a statistics exam. (Made-up data.) Are study method and exam result related? Use α = 0.05.

Observed counts: study method and exam result
Study methodPassedDid not passTotal
Flashcards7842120
Rereading notes484290
Practice tests721890
Total198102300

Hypotheses. H₀: study method and exam result are independent. Hₐ: they are associated.

Expected. Use row total × column total ÷ 300. For flashcards and passed, that’s 120 × 198 / 300 = 79.2. Leave the decimal in. You can’t have 79.2 students, but you can have an average of that over many samples.

Expected counts, with each cell’s contribution in parentheses
Study methodPassedDid not pass
Flashcards79.2 (0.018)40.8 (0.035)
Rereading notes59.4 (2.188)30.6 (4.247)
Practice tests59.4 (2.673)30.6 (5.188)

Compute. Adding all six contributions gives χ² ≈ 14.35.

Decide. df = (3 − 1)(2 − 1) = 2, so the critical value is 5.991. Since 14.35 is above that (p ≈ 0.0008), reject H₀.

In context. There is strong evidence that study method and exam result are associated. The biggest contributions are in the “did not pass” column: rereading has more than expected and practice tests have fewer. This was a survey, not an experiment, so it doesn’t show that the method caused the difference. Stronger students might simply choose practice tests.

Example 4: When the setup needs fixing first

Problem: expected counts are too small. A professor checks 30 grades against a curve. Three expected counts are below 5, so the usual chi-square approximation does not meet this guide’s rule yet. Merge neighbors that make sense together, based on the expected counts and not on which merge gives the result you’d like.

Grade curve for 30 students
GradeClaimed shareEAfter merging
A10%3A or B: 12
B30%9(merged)
C40%12C: 12
D15%4.5D or F: 6
F5%1.5(merged)

Now there are 3 categories, all with E of at least 5, so df drops from 4 to 2. Add up the observed counts the same way before computing χ². This now tests the three combined shares; it cannot detect differences within A/B or D/F.

Problem: the data are given as percents. Suppose 60% of people pick A and 40% pick B, against a claim of 50/50. If n = 10, the counts are 6 and 4, and χ² = 0.4. If n = 100, the counts are 60 and 40, and χ² = 4.0. Same percents, ten times the statistic. If you plug percents into the formula you’re pretending n = 100, so always convert back to counts.

Want more of this with your own course’s chapters? Try StatsDrill free for 3 days. No card needed.

Practice problems

For these exercises, assume independent observations, appropriate random sampling, and samples under 10% of their populations when sampling without replacement. All goodness-of-fit shares are specified in advance. Three rounds, getting harder as you go. Type or choose an answer, press Check answer, and retry as often as you like. Each one has a full solution.

Round 1: Name the test

1. A candy maker claims its bags are 20% red, 30% blue, 30% green and 20% yellow. You count the colors in 400 candies. Which test fits?
Show solution 1

Goodness of fit. There is one variable (color) and a claimed share for each category. That is goodness of fit.

Why the other choices are wrong:

  • Test of independence: You only recorded one variable, color. The claimed percentages are not a second variable.
  • Test of homogeneity: There is one sample and it is being compared with a claim, not with another group.
  • Not a chi-square test: These are counts in categories, so a chi-square test does fit here.
2. You survey 500 randomly chosen students and record each one’s college (science, arts or business) and whether they have a part-time job. Which test fits?
Show solution 2

Test of independence. One sample, two categorical variables, and the question is whether they are related. That is a test of independence.

Why the other choices are wrong:

  • Goodness of fit: Two variables were recorded for each student, so one set of claimed shares would not cover it.
  • Test of homogeneity: Close, and the arithmetic is the same. But this is one sample. Nobody chose how many students came from each college.
  • Not a chi-square test: These are counts in categories, so a chi-square test does fit here.
3. You randomly sample 150 students from each of three campuses and ask each one which meal plan they prefer. Do preferences differ by campus? Which test fits?
Show solution 3

Test of homogeneity. You fixed the sample size for each campus in advance and compared one variable across them. That is homogeneity.

Why the other choices are wrong:

  • Goodness of fit: There is no claimed distribution here. You are comparing the campuses with each other.
  • Test of independence: Close, and the arithmetic is the same. But the three campuses were sampled separately, which points to homogeneity.
  • Not a chi-square test: These are counts in categories, so a chi-square test does fit here.
4. You compare the average weekly study hours of students who live on campus with those who commute. Which test fits?
Show solution 4

Not a chi-square test. Study hours are a number and you are comparing means, so this is a two-sample t test.

Why the other choices are wrong:

  • Goodness of fit: Average hours are numerical, not counts in categories.
  • Test of independence: Average hours are numerical, not counts in categories. Compare two means with a t test.
  • Test of homogeneity: Average hours are numerical, not counts in categories. Compare two means with a t test.

Round 2: Run the numbers

The critical value table is in the method section if you need it. Decimals are fine.

5. You roll a die 120 times to test whether it is fair. What is the expected count for each face?

Show solution 5

20. Each face should get 1/6 of the rolls: 120 × 1/6 = 20.

6. A club claims its members are 50% first-years, 30% second-years and 20% upper-level students. You sample 240 members. What is the expected count of second-years?

Show solution 6

72. Expected count = sample size × claimed share = 240 × 0.30 = 72.

7. A goodness-of-fit test has 6 categories and a sample of 300. What are the degrees of freedom?

Show solution 7

5. df = k − 1 = 6 − 1 = 5. The sample size does not enter.

8. In a two-way table of 200 people, a cell’s row total is 80 and its column total is 120. What is the expected count for that cell?

Show solution 8

48. E = (80 × 120) / 200 = 9600 / 200 = 48.

9. What are the degrees of freedom for a test of independence on a table with 3 rows and 4 columns?

Show solution 9

6. df = (r − 1)(c − 1) = (3 − 1)(4 − 1) = 2 × 3 = 6.

10. A cell has observed count 30 and expected count 24. What does it add to the chi-square statistic?

Show solution 10

1.5. (30 − 24)² / 24 = 36 / 24 = 1.5.

11. You test whether three brands are equally popular among 90 shoppers. The counts are 20, 25 and 45. What is the chi-square statistic? Round to two decimal places.

Show solution 11

11.67. E = 30 for each brand. (−10)²/30 + (−5)²/30 + 15²/30 = 11.666… ≈ 11.67. Keep the unrounded contributions until the final step.

12. A goodness-of-fit test with 4 categories gives χ² = 6.20. Using α = 0.05, what do you decide?
Show solution 12

Fail to reject H₀, because 6.20 is below 7.815. df = 4 − 1 = 3, so the critical value is 7.815. Since 6.20 is less than 7.815, fail to reject H₀. (The chi-square approximation gives p ≈ 0.102.)

Why the other choices are wrong:

  • Reject H₀, because 6.20 is bigger than the critical value: df = 3, so the 0.05 critical value is 7.815, and 6.20 is below it.
  • Fail to reject H₀, because 6.20 is above 3.841: 3.841 is the critical value for df = 1. With 4 categories, df = 3.
  • Reject H₀, because the test is two-tailed: Chi-square tests like this one use only the right tail.

Round 3: One full problem, start to finish

A random sample of 200 students reports whether they went to an optional review session and whether they passed the midterm. (Made-up data.) Test whether attendance and passing are related at α = 0.05. H₀: attendance and passing are independent in the population. Hₐ: they are associated.

Observed counts: review session and exam result
Review sessionPassedDid not passTotal
Attended641680
Skipped7644120
Total14060200

13. Step 1. Find all four expected counts.

Show solution 13

56, 24, 84, 36. 80 × 140/200 = 56, 80 × 60/200 = 24, 120 × 140/200 = 84, 120 × 60/200 = 36. All are at least 5, so the expected-count condition is met.

14. Step 2. Add up (O − E)²/E across the four cells. Round to two decimal places.

Show solution 14

6.35. Each cell is off by 8, so each top is 64. 64/56 + 64/24 + 64/84 + 64/36 = 1.14 + 2.67 + 0.76 + 1.78 = 6.35.

15. Step 3. What are the degrees of freedom?

Show solution 15

1. df = (2 − 1)(2 − 1) = 1.

16. Step 4. Using α = 0.05, what is the decision?
Show solution 16

Reject H₀. 6.35 is above the df = 1 critical value of 3.841 (p ≈ 0.012), so reject H₀.

Why the other choices are wrong:

  • Fail to reject H₀: Compare 6.35 with the df = 1 critical value, 3.841. It is above that line, so it lands in the rejection region.
17. Step 5. Which conclusion is the best one to write?
Show solution 17

There is evidence that review attendance and passing are associated in this population. Reject H₀ means evidence of association. Since students were not randomly assigned, it does not show that the session caused the higher pass rate.

Why the other choices are wrong:

  • Going to the review session causes students to pass.: Students chose whether to attend, so other differences could explain the gap. A chi-square test shows association, not cause.
  • Attendance and passing are proven to be dependent.: A test gives evidence, not proof.
  • 80% of attendees passed, so the p-value is 0.80.: A sample percent is not a p-value. The p-value here is about 0.012.

Answer key

Open all answers
  1. Goodness of fit. There is one variable (color) and a claimed share for each category. That is goodness of fit.
  2. Test of independence. One sample, two categorical variables, and the question is whether they are related. That is a test of independence.
  3. Test of homogeneity. You fixed the sample size for each campus in advance and compared one variable across them. That is homogeneity.
  4. Not a chi-square test. Study hours are a number and you are comparing means, so this is a two-sample t test.
  5. 20. Each face should get 1/6 of the rolls: 120 × 1/6 = 20.
  6. 72. Expected count = sample size × claimed share = 240 × 0.30 = 72.
  7. 5. df = k − 1 = 6 − 1 = 5. The sample size does not enter.
  8. 48. E = (80 × 120) / 200 = 9600 / 200 = 48.
  9. 6. df = (r − 1)(c − 1) = (3 − 1)(4 − 1) = 2 × 3 = 6.
  10. 1.5. (30 − 24)² / 24 = 36 / 24 = 1.5.
  11. 11.67. E = 30 for each brand. (−10)²/30 + (−5)²/30 + 15²/30 = 11.666… ≈ 11.67. Keep the unrounded contributions until the final step.
  12. Fail to reject H₀, because 6.20 is below 7.815. df = 4 − 1 = 3, so the critical value is 7.815. Since 6.20 is less than 7.815, fail to reject H₀. (The chi-square approximation gives p ≈ 0.102.)
  13. 56, 24, 84, 36. 80 × 140/200 = 56, 80 × 60/200 = 24, 120 × 140/200 = 84, 120 × 60/200 = 36. All are at least 5, so the expected-count condition is met.
  14. 6.35. Each cell is off by 8, so each top is 64. 64/56 + 64/24 + 64/84 + 64/36 = 1.14 + 2.67 + 0.76 + 1.78 = 6.35.
  15. 1. df = (2 − 1)(2 − 1) = 1.
  16. Reject H₀. 6.35 is above the df = 1 critical value of 3.841 (p ≈ 0.012), so reject H₀.
  17. There is evidence that review attendance and passing are associated in this population. Reject H₀ means evidence of association. Since students were not randomly assigned, it does not show that the session caused the higher pass rate.

Mistakes that cost points

Common chi-square mistakes and fixes
MistakeFix
Running the test on percentsUse raw counts. Percents throw away the sample size, and χ² depends on it.
Rounding expected counts to whole numbersKeep the decimals. An expected count of 59.4 is fine.
Dividing by OAlways divide by E, the expected count.
Using n − 1 for dfUse k − 1 or (r − 1)(c − 1). The sample size is not part of it.
Doubling the p-valueUse the right tail only, even if the question says “different.”
Saying “H₀ is proven”Say there is not enough evidence to reject it.
Saying one variable causes the otherSay they are associated, unless the study was a randomized experiment.

Common questions

What is the difference between goodness of fit and a test of independence?

Count your variables. Goodness of fit has one categorical variable and compares its counts with claimed shares. A test of independence has two categorical variables measured on the same sample and asks whether they are related.

What is the difference between a test of independence and a test of homogeneity?

The arithmetic is identical. The difference is how the data were collected. Independence takes one sample and records two variables. Homogeneity takes separate samples from two or more groups and compares the distribution of one variable across them.

Is a chi-square test always right-tailed?

For these tests, yes. Each contribution is squared, so any gap between observed and expected makes the statistic bigger. Only large values count as evidence against the null hypothesis, so you use the right tail even when the question says the counts differ.

What do I do if an expected count is below 5?

Follow your course’s expected-count rule. In a goodness-of-fit test, combine categories only when that grouping makes sense for the question, without choosing a grouping to get a desired result. Add both observed and expected counts and recompute df. If combining is not appropriate, use an exact or simulation method; Fisher’s exact test is an option for a small 2 × 2 table.

Is a 2 × 2 chi-square test the same as a two-proportion z test?

For a 2 × 2 table, the uncorrected Pearson chi-square statistic equals the pooled two-proportion z statistic squared. Its p-value matches the two-sided z test. Yates’s continuity correction can reduce the chi-square statistic and increase the p-value, so check your software and course convention. All calculations here are uncorrected.

How do you use a chi-square test in genetics?

It is a goodness-of-fit test. Turn the predicted ratio into expected counts, such as 9/16, 3/16, 3/16 and 1/16 of the total for a dihybrid cross with independent assortment and complete dominance, then use degrees of freedom equal to the number of phenotypes minus 1. A small statistic means the data are consistent with the ratio, not that the ratio is proven.

Keep practicing

Try 3 days free

3-day free trial, no card needed.

Related guides

Sources and fact checks

Methods were checked against these references. Example 2 uses Mendel’s published counts (the translation says “angular” where modern books say “wrinkled”). All other example and practice datasets are fictional.