Chi-Square Goodness of Fit Test

April 12, 2026

Problem

Roll a die 120 times: observed {18,22,16,20,24,20}. Is it fair? Expected: 20 each. Compute χ² and p-value.

Explanation

What is the chi-square goodness of fit test?

The χ2\chi^2 test checks whether observed frequencies match expected frequencies. Is the die fair? Are the survey responses distributed as expected?

The formula

χ2=(OiEi)2Ei\chi^2 = \sum \frac{(O_i - E_i)^2}{E_i}

where OiO_i = observed count and EiE_i = expected count for each category.

Step-by-step: Is this die fair?

Data: 120 rolls. Observed: {18,22,16,20,24,20}\{18, 22, 16, 20, 24, 20\}. If fair, expected: 120/6=20120/6 = 20 for each face.

Step 1 — State hypotheses.

H0H_0: Die is fair (all faces equally likely). HaH_a: Die is not fair.

Step 2 — Compute χ2\chi^2:

χ2=(1820)220+(2220)220+(1620)220+(2020)220+(2420)220+(2020)220\chi^2 = \frac{(18-20)^2}{20} + \frac{(22-20)^2}{20} + \frac{(16-20)^2}{20} + \frac{(20-20)^2}{20} + \frac{(24-20)^2}{20} + \frac{(20-20)^2}{20}

=420+420+1620+020+1620+020=0.2+0.2+0.8+0+0.8+0=2.0= \frac{4}{20} + \frac{4}{20} + \frac{16}{20} + \frac{0}{20} + \frac{16}{20} + \frac{0}{20} = 0.2 + 0.2 + 0.8 + 0 + 0.8 + 0 = 2.0

Step 3 — Degrees of freedom: df=categories1=61=5df = \text{categories} - 1 = 6 - 1 = 5.

Step 4 — Find the p-value. From a χ2\chi^2 table with df=5df = 5: χ2=2.0\chi^2 = 2.0 gives p0.85p \approx 0.85.

Step 5 — Decision. p=0.85>0.05p = 0.85 > 0.05. Fail to reject H0H_0. No evidence the die is unfair — the deviations are within normal random variation.

Interpreting the χ2\chi^2 value

  • Large χ2\chi^2 (small p-value): observed is far from expected → reject H0H_0.
  • Small χ2\chi^2 (large p-value): observed is close to expected → fail to reject.

Try it in the visualization

Adjust the observed counts for each face. The bar chart compares observed vs expected. χ2\chi^2 and the p-value update live. Adjust counts to make the die obviously unfair and see χ2\chi^2 spike.

Interactive Visualization

Parameters

18.00
22.00
16.00
20.00
24.00
20.00
Your turn

Got your own math or physics problem?

Turn any problem into an interactive visualization like this one — powered by AI, generated in seconds. Free to try, no credit card required.

Sign Up Free to Try It30 free visualizations every day
Chi-Square Goodness of Fit Test | MathSpin