Chi-Square Test Calculator
Perform a chi-square goodness-of-fit test comparing observed and expected frequencies across four categories.
About this calculator
This calculator runs a chi-square goodness-of-fit test across four fixed categories, summing (observed − expected)² / expected for each (lines 20-23) and converting the total into an approximate p-value via a Wilson-Hilferty chi-square-to-normal transformation (lines 29-37) rather than an exact chi-square table lookup. Degrees of Freedom is always 3 — the category count minus one (line 25) — regardless of what you type into any observed or expected field, because it comes purely from the four-cell structure of this test, not from the data. At the defaults, Chi-Square = 6.25 with a p-value near 0.098, which the calculator reports as not significant at either α=0.05 or α=0.01, despite a fairly large-looking statistic.
Each Expected Count field falls back to 1 via a boolean-OR default (lines 8-11), so typing a literal 0 does not zero it out — it becomes 1 instead, the same as leaving the field blank. That fallback also makes an internal safety check dead code: the summation guards against a zero expected value with `if (e === 0) return sum` (line 21), but e can never actually be 0 by the time it reaches that line, since the boolean-OR fallback already replaced any 0 upstream. What this does not account for: a negative Expected Count is not blocked or clamped anywhere in the engine itself (only the input's UI minimum of 0.01 discourages it), and a negative expected value flips that cell's contribution to the sum negative, which can artificially shrink Chi-Square below what a valid goodness-of-fit test would ever produce.
Inputs
Results
Chi-Square Statistic (χ²)
6.25
P-Value (approx)
0.1
How to Use This Calculator
- Enter Observed Count 1, Expected Count 1, and Observed Count 2.
- Set Expected Count 2, Observed Count 3, and Expected Count 3.
- Adjust Observed Count 4, Expected Count 4 as needed.
- Review Chi-Square Statistic (χ²) and P-Value (approx).
- Use Degrees of Freedom and Significant at α=0.05 (1=Yes) to inform your decision.
How the result changes with Observed Count 1
| Observed Count 1 | Chi-Square Statistic (χ²) | P-Value (approx) |
|---|---|---|
| 25 | 9.38 | 0.02 |
| 38 | 3.85 | 0.28 |
| 75 | 34.38 | 0 |
| 125 | 184.38 | 0 |
What each input means
- Observed Count 1
- Observed frequency for the first category.
- Expected Count 1
- Expected frequency for the first category under the null hypothesis.
- Observed Count 2
- Observed frequency for the second category.
- Expected Count 2
- Expected frequency for the second category under the null hypothesis.
- Observed Count 3
- Observed frequency for the third category.
- Expected Count 3
- Expected frequency for the third category under the null hypothesis.
- Observed Count 4
- Observed frequency for the fourth category.
- Expected Count 4
- Expected frequency for the fourth category under the null hypothesis.
How this is calculated
Worked example, using the default values
- Identify Input Parameters4 parametersObserved Count 1 = 50, Expected Count 1 = 40, Observed Count 2 = 30, Expected Count 2 = 40 = 8 input(s) provided
- Calculate Chi-Square StatisticChi-Square Statistic6.25 = 6.25
- Calculate P-ValueP-Value0.0984 = 0.0984
- Calculate Degrees of FreedomDegrees of Freedom = df3 = 3
- Calculate Significant at α=0.05Significant at α=0.050 = 0
Engine last updated . Checked against 2 independently-derived tests — how we verify calculators. Built by Paul Gunder, a software engineer, not a licensed financial, medical, or legal professional.
Frequently Asked Questions
Why does Degrees of Freedom never change no matter what values I enter?
Because it isn't derived from your data at all — it's fixed at the number of categories minus one, and this calculator hard-codes four categories, so Degrees of Freedom is always 3 (line 25). Only switching to a test with a different number of categories would change it, and this calculator doesn't offer that option.
What happens if I type 0 into an Expected Count field?
It does not register as 0. Every expected-count field falls back to 1 via a boolean-OR default (lines 8-11), and JavaScript's `||` treats a literal 0 the same as a missing value, silently substituting 1 — so a 0 entry quietly becomes 1 rather than triggering any zero-expected-value handling elsewhere in the calculation.
Is there really a check in this calculator for a zero Expected Count, and does it ever run?
There is a line for it — `if (e === 0) return sum` (line 21) — but it can never fire in practice. By the time execution reaches it, every expected value has already passed through the `|| 1` fallback (lines 8-11), which replaces any literal 0 with 1 before the summation loop even starts, so the guard is effectively dead code.
Why does the calculator's own default example come back as not statistically significant?
With the default observed and expected counts, Chi-Square works out to 6.25 across 3 degrees of freedom, which this calculator's approximation puts the p-value at roughly 0.098 — above the conventional 0.05 cutoff, so Significant at α=0.05 reads 0 even though the statistic itself looks moderately large at first glance.
Related Calculators
The questions that sit next to this one — chosen by subject, including calculators filed under a different category.
T-Test Calculator
Calculate the t-statistic, degrees of freedom, and approximate p-value for a one-sample t-test.
StatisticsFisher's Exact Test Calculator
Perform Fisher's exact test on a 2x2 contingency table to determine if there is a significant association between two categorical variables.
StatisticsMultiple Regression Calculator
Evaluate a multiple regression model using SSR, SSE, number of predictors, and sample size. Calculate R², adjusted R², F-statistic, and model fit metrics.
More in Math & Statistics.