NOTACAL logo

Chi-Square Calculator

Chi-Square Calculator

Give us your feedback! Was this useful?

Introduction

The chi-square test is the standard method for checking whether observed categorical counts match what we would expect under some hypothesis. It is used whenever the data are counts sorted into categories: survey responses by preference, blood types in a sample, the colors of cars in a parking lot, or the number of defective units across production shifts.

The core idea is simple. For each category you compare the observed count O to the expected count E under the null hypothesis. Categories where observation and expectation diverge a lot contribute more to the total chi-square statistic. Summing the squared, standardized deviations across all categories gives one number that summarizes the overall mismatch.

Our chi-square calculator takes two comma-separated lists of equal length — the observed counts and the expected counts — and returns the chi-square statistic χ² and the degrees of freedom (number of categories minus one). A larger χ² means the data disagree more strongly with the expectation.

Developed by Karl Pearson in 1900, the chi-square test was one of the first rigorous tools for categorical data and remains essential in genetics, market research, quality control, and the social sciences. It turns a table of counts into a single, interpretable measure of surprise.

The test is fundamentally a measure of discrepancy. Each category contributes (O − E)² / E to the total, so categories where observation and expectation agree contribute almost nothing, while a single large deviation can dominate the statistic. This additive structure is also its diagnostic power: by inspecting the per-category contributions, you can see exactly which category drove the result, rather than only knowing that something disagreed overall.

The expected counts are not arbitrary; they encode the null hypothesis. In a fairness test for a die, the expectation is equal counts across faces. In a genetics cross, the expectation comes from Mendelian ratios. In a survey, it might come from a previously measured population proportion. Getting the expected counts right is therefore as important as recording the observed counts, because the chi-square statistic is meaningless without a well-defined expectation to compare against.

How to Use This Calculator

Enter the observed counts as a comma-separated list, then the expected counts as a second list of the same length. Each expected value must be positive. Press Calculate to get χ² and the degrees of freedom.

Example 1 — Dice fairness. Roll a die 60 times. Observed: 8,12,9,11,10,10. Expected if fair: 10 per face. χ² = (4+4+1+1+0+0)/10 = 1.0 with 5 df, a small value consistent with a fair die.

Example 2 — Survey preference. Observed choices among 3 options: 30,40,30 (total 100). Expected if equal: 33.33 each. χ² = (11.09+11.09+11.09)/33.33 ≈ 1.00 with 2 df.

Edge cases. If the two lists differ in length, or either has fewer than two entries, the calculator returns nothing. Expected counts of zero or negative are rejected because division by zero or a negative expected frequency is invalid. A χ² of 0 means every observed count exactly equals expected, a perfect fit.

Example 3 — Genetic ratio. Expected 9:3:3:1 across four phenotypes with totals 240. Observed 130,45,42,23. The largest contribution comes from the first category, and the total χ² indicates whether the observed departure from the classic ratio is plausible by chance.

Example 4 — Survey with three options. Observed 50,30,20 against expected 33.3 each. χ² ≈ 14.0 with 2 df, well above the 5% critical value of 5.99, so the preferences are clearly not equal.

Example 5 — Perfect match. Observed 10,10,10 against expected 10,10,10 gives χ² = 0 and df = 2, the ideal fit with no discrepancy at all.

The Formula

The chi-square statistic is the sum over categories of the squared difference between observed and expected, divided by expected:

χ2=i=1k(OiEi)2Ei\chi^2 = \sum_{i=1}^{k} \frac{(O_i - E_i)^2}{E_i}
[nist-chisq]

where Oᵢ is the observed count, Eᵢ is the expected count, and k is the number of categories. The degrees of freedom for a goodness-of-fit test are:

df=k1df = k - 1

Manual Step-by-Step

Observed: 30, 40, 30. Expected: 33.33, 33.33, 33.33.

  • (30 − 33.33)² / 33.33 = 11.09 / 33.33 = 0.333
  • (40 − 33.33)² / 33.33 = 44.41 / 33.33 = 1.333
  • (30 − 33.33)² / 33.33 = 0.333
  • χ² = 0.333 + 1.333 + 0.333 = 2.00; df = 3 − 1 = 2

The calculator performs these sums with full precision and reports χ² and df directly.

Chi-Square Reference

Contributions for a Three-Category Test

CategoryObservedExpected(O−E)²/E
A3033.330.33
B4033.331.33
C3033.330.33

The table breaks the total χ² = 2.00 into its category contributions. Category B drives almost all of the discrepancy, contributing about two-thirds of the statistic. With 2 degrees of freedom, a χ² of 2.00 is well below the 5% critical value of 5.99, so the data are consistent with the equal-preference hypothesis.

Chi-square contributions (O-E)^2/E by category. Category B accounts for most of the total discrepancy.

Practical Tips

  • Ensure expected counts are all positive; zero or negative expectations break the formula.
  • For valid inference, most expected counts should be at least 5; collapse sparse categories if needed.
  • Keep observed and expected the same length and in the same category order.
  • Compare χ² to the critical value for your df at the chosen significance level, not just the raw number.
  • Use this goodness-of-fit version for one sample against a fixed expectation; use a test of independence for a contingency table.
  • Report both χ² and df; the same χ² means different things at different df.
  • Inspect the per-category contributions to learn which category drives a large χ² rather than only noting the total.
  • Ensure every expected count comes from a clearly stated null hypothesis so the comparison is meaningful.
  • When expected counts are small, merge adjacent categories to raise them above the minimum rather than discarding data.
  • Keep your totals consistent: the sum of observed should equal the sum of expected by construction of the hypothesis.
  • Compare χ² to the critical value for your exact df; published critical values are indexed by degrees of freedom.
  • Report the p-value when possible, because the bare χ² leaves the significance ambiguous without a reference table.
  • Use a continuity correction only for special 2-category cases; the standard formula here is for general goodness-of-fit.
  • Remember the test is two-tailed in spirit: it flags any departure from expectation, high or low.

Limitations

  • The chi-square test requires counts, not percentages or averaged measurements.
  • It assumes each observation falls into exactly one category and categories are mutually exclusive.
  • Expected frequencies that are too small make the chi-square approximation unreliable.
  • It detects any deviation from expectation but not which direction or why without inspecting contributions.
  • The test is not valid if the total observed does not equal the total expected by construction of the hypothesis.
  • A non-significant result does not prove the null is true, only that the data do not contradict it enough.

From Statistic to Decision

The chi-square value by itself is not a verdict; it becomes one only when compared against the critical value for your degrees of freedom at a chosen significance level. At the conventional 5% level, the critical χ² is 3.84 for 1 df, 5.99 for 2 df, 7.81 for 3 df, and 9.49 for 4 df. If your computed statistic exceeds the critical value, you reject the null hypothesis of a good fit; if not, you retain it pending better evidence.

Degrees of freedom are the key that unlocks the critical value. For a single-sample goodness-of-fit test they equal the number of categories minus one, because once you know the total and all but one category's expectation, the last is fixed. Using the wrong df is a common error that makes a result look significant or insignificant by mistake, which is why the calculator reports df explicitly.

The per-category contributions are often more informative than the total. A χ² of 10 might be driven entirely by one unexpected category while the rest fit perfectly, or it might be a uniform moderate mismatch across all categories. Those two stories have very different implications for what to investigate next, and only the contribution breakdown reveals which is true.

Finally, a goodness-of-fit test can reject the null without telling you what the true distribution is. It is a screen, not a model builder. After flagging a poor fit, you still need domain knowledge or a different model to say what the data are actually doing.

When the Chi-Square Test Misleads

The chi-square goodness-of-fit test is sensitive to how the data are prepared, and several common mistakes invalidate its result. The most serious is small expected counts. The chi-square approximation to the p-value relies on the expected frequency in each category being reasonably large, conventionally at least 5. When a category has an expected count of 1 or 2, its (O − E)² / E term behaves erratically and the overall p-value becomes untrustworthy. The fix is to merge small categories or collect more data, not to ignore the warning.

Choosing the wrong expected counts is the second failure. The expected frequencies must encode a clear, pre-specified null hypothesis. If you derive them from the observed data, for instance by setting expected equal to the observed proportions, the test becomes circular and will never reject. Expected counts should come from theory, a previous study, or an external standard, never from the sample being tested.

Independence of observations is assumed as well. If the same individuals contribute multiple counts, or categories overlap so one observation lands in several, the chi-square statistic overstates the evidence. Each observation must fall into exactly one category, and categories must be mutually exclusive and exhaustive.

Finally, a non-significant result is not proof that the null is true; with a small sample even a badly misspecified expectation can produce a χ² too small to reject. The test has low power when n is tiny, so a "good fit" with few observations means little. Report the sample size and the contributions alongside the statistic so the reader can judge whether the test had the power to detect a real discrepancy.

Frequently Asked Questions

What does the chi-square statistic measure?
It measures the total standardized discrepancy between observed and expected counts. Larger values mean the data deviate more from what the hypothesis predicted.
Why subtract 1 for degrees of freedom?
Because the expected counts are constrained to sum to the total observations, one degree of freedom is lost for that constraint, leaving k minus 1.
What is a good chi-square value?
There is no universal good value. You compare χ² to the critical value for your degrees of freedom at a chosen significance level; larger than critical means reject the null.
Can expected counts be zero?
No. Division by zero is undefined, and a zero expected count usually means a category should be merged with another or the model is misspecified.
Is this the same as a chi-square test of independence?
The formula is the same, but this calculator does goodness-of-fit against a fixed expectation. A test of independence uses a two-way contingency table and different df.
What sample size do I need?
Enough that most expected counts are at least 5. With very small samples the chi-square approximation to the p-value is unreliable.
Why did the calculator return no result?
Usually the two lists differ in length, have fewer than two entries, or contain a non-positive expected count. Check your inputs.
Does a small chi-square prove the model is correct?
No. It only means the data do not disagree with the expectation enough to reject it; the model could still be wrong in ways this test does not detect.
Can I use percentages instead of counts?
No. The test requires raw counts. Convert percentages back to counts using the total sample size before entering them.
Who invented the chi-square test?
Karl Pearson introduced the chi-square test in 1900, making it one of the earliest formal methods for analyzing categorical data.

Reporting a Chi-Square Result

A chi-square result is most useful when reported with its components, not just the headline statistic. Give the χ² value, the degrees of freedom, and the p-value together, because the same χ² means different things at different df and is uninterpretable without the p-value or a stated critical value. A reader should be able to see immediately whether the test rejected the null at the chosen level.

Include the per-category contributions, or at least name the category that drove the result, so the finding is diagnosable rather than opaque. A χ² of 14 could come from one wildly off category or from a uniform moderate mismatch, and those two stories lead to entirely different follow-up actions. Showing the contributions turns a single number into a starting point for investigation.

State the expected counts and their source, because the expected frequencies encode the hypothesis being tested. If they came from a theoretical ratio, a prior study, or an external standard, say which; if they were derived from the observed data, the test is invalid and that must be acknowledged. Finally, note the sample size, since a "good fit" from a tiny sample is weak evidence and a "poor fit" from a large one may reflect trivial departures that are statistically detectable but practically unimportant.

A useful habit is to report the chi-square result alongside the actual observed and expected counts in a small table, because the statistic compresses information that readers often want to see for themselves. Showing the table lets a skeptic verify the contributions and notice patterns the single number hides, such as one category carrying the entire discrepancy. Transparency about both the summary and the underlying counts is what turns a goodness-of-fit test from a black box into a shared, checkable piece of evidence.

Last updated: July 20, 2026

1b

UnByte — Independent Software Engineering

Every calculator references authoritative sources — Editorial policy