Chi-Square Goodness of Fit Calculator

The chi-square goodness-of-fit test checks whether observed counts match an expected pattern. For counts 5, 8, 9, 8, 10, 20 with equal expected counts of 10, χ² = 13.4 with 5 degrees of freedom and p = 0.0199, so you reject the idea that the counts are evenly spread at α = 0.05.

Last updated · By · Runs in your browser, nothing is uploaded

Advanced options
Result

Step-by-Step Solution

Enter your values above to see the full working.

What Is a Chi-Square Test?

A chi-square (χ²) goodness-of-fit test compares the counts you actually observed in several categories with the counts you would expect if some hypothesis were true. It answers one question: are the differences between observed and expected large enough that chance alone is an unlikely explanation?

The test is built for counts of categories, such as how many times each face of a die landed up, how many customers chose each plan, or how many plants showed each genetic trait. It is not for averages or measurements. Because it needs only counts and a hypothesis about their proportions, it is one of the most widely used tests in statistics.

Two Common Chi-Square Tests

TestQuestion it answersData layoutThis calculator
Goodness of fitDo the counts in one categorical variable match an expected distribution?One row of countsYes
Test of independenceAre two categorical variables related?A table with rows and columnsNo (use a contingency table tool)

Chi-Square Formula

χ² = Σ (O − E)² ÷ E degrees of freedom = k − 1
  • O is the observed count in a category.
  • E is the expected count in that category under the null hypothesis.
  • Σ adds the result over all k categories.
  • k − 1 degrees of freedom apply because once k − 1 counts are known, the last is fixed by the total.

When you leave the expected counts blank, the calculator assumes every category is equally likely and sets E = total ÷ k. A large χ² means the observed counts sit far from the expectation. The p-value is the chance of a χ² at least that large if the null hypothesis were true, found from the chi-square distribution. You can look up thresholds with the critical value calculator.

Worked Example: Is the Die Fair?

A die is rolled 60 times. The faces 1 to 6 appear 5, 8, 9, 8, 10 and 20 times. If the die were fair, each face would be expected 60 ÷ 6 = 10 times.

FaceObserved OExpected EO − E(O − E)² ÷ E
1510−52.5
2810−20.4
3910−10.1
4810−20.4
5101000
620101010
Total6060013.4
  1. χ² statistic: 2.5 + 0.4 + 0.1 + 0.4 + 0 + 10 = 13.4.
  2. Degrees of freedom: 6 − 1 = 5.
  3. Critical value at α = 0.05: 11.0705.
  4. p-value: 0.0199.
  5. Decision: 13.4 > 11.0705 and p < 0.05, so reject the null hypothesis. The counts are unlikely to come from a fair die.

The table also shows where the problem is: face 6 alone contributes 10 of the 13.4, so a surplus of sixes is driving the result.

Unequal Expected Counts: A Genetics Example

A cross predicts a 3 : 1 ratio of two traits. Out of 400 offspring you see 290 and 110, where 300 and 100 were expected. χ² = (290 − 300)² ÷ 300 + (110 − 100)² ÷ 100 = 0.3333 + 1 = 1.3333 with 1 degree of freedom, giving p = 0.2482. The data are consistent with the 3 : 1 ratio.

How to Use This Chi-Square Calculator

  1. Enter your observed counts, separated by commas or spaces, one per category.
  2. Enter the expected counts in the same order. Leave this box blank if all categories should be equally likely.
  3. Choose the significance level α, usually 0.05.
  4. Read χ², the degrees of freedom, the p-value, the critical value and the decision. The steps show each category’s contribution.

The expected counts must add up to the same total as the observed counts. If you only have proportions, multiply each by the total number of observations first.

Real-World Uses of the Chi-Square Test

  • Genetics: checking offspring ratios against Mendelian predictions.
  • Marketing: testing whether customers favour some options more than chance would explain.
  • Quality control: checking whether defects are spread evenly across shifts or machines.
  • Elections and surveys: comparing a sample’s composition with known population shares.
  • Games and fairness: testing dice, cards or random number generators for bias.

What Are the Most Common Mistakes With the Chi-Square Goodness of Fit Calculator?

  • Using percentages instead of counts. The test needs actual counts. Percentages change χ² completely.
  • Expected counts that are too small. The usual rule is that every expected count should be at least 5. Combine categories if not.
  • Non-independent observations. Each observation should fall in exactly one category and be independent of the others.
  • Wrong degrees of freedom. For goodness of fit with no estimated parameters, use k − 1.
  • Reading significance as size. A significant result says the pattern is not chance, not how large the departure is.
  • Fishing for categories. Decide the categories and expected proportions before looking at the data.

Where Can You Verify These Formulas?

The definitions and formulas on this page follow standard references. Check them against these sources:

Built and maintained by S. Dilshan. Found a mistake? Email [email protected] with the page address.

Frequently Asked Questions

What does a chi-square test tell you?

It tells you whether the differences between observed and expected counts are larger than chance would normally produce. A small p-value suggests the observed pattern does not match the expected one.

How do you calculate chi-square?

For each category, subtract the expected count from the observed count, square it and divide by the expected count. Add those values up to get χ². Degrees of freedom are the number of categories minus one.

What is a good p-value for a chi-square test?

If the p-value is below your significance level, usually 0.05, you reject the null hypothesis. If it is above, you do not have enough evidence to reject it.

What if my expected counts are less than 5?

The chi-square approximation becomes unreliable. Combine neighbouring categories or use an exact test such as the multinomial or Fisher’s exact test.

What is the difference between goodness of fit and independence tests?

Goodness of fit compares one categorical variable with an expected distribution. A test of independence uses a table of two categorical variables to see whether they are associated.

Can a chi-square value be negative?

No. Every term is a square divided by a positive expected count, so χ² is always zero or greater. It equals zero only when observed and expected counts match exactly.