Math calculator

Goodness of Fit Calculator

Observed against expected, with the cell that produced the result named.

Observed against expected, cell by cell

Chi-square 11.60 on 5 df, p = 0.0407. Face 3 alone supplies 8.10 of the 11.60 — 70% of the whole statistic.

6 categories, 60 observations, 5 degrees of freedom

χ² = 11.600000, p = 0.040699

Every cell expects at least 10.0000, so the chi-square approximation is on solid ground. The observed counts differ from the expected ones by more than chance explains.

Chi-square

11.600000

df = 5

p-value

0.040699

upper tail

Smallest expected

10.00000

above the floor of 5

Largest contributor

8.10000

category 3, 69.8% of χ²

Each category with its observed and expected counts, contribution to the statistic and standardised residual
CategoryObservedExpectedO − EContribution to χ²Std. residual
18.00000010.00000-2.000000.40000-0.6325
29.00000010.00000-1.000000.10000-0.3162
319.00000010.00000+9.000008.10000+2.8460
45.00000010.00000-5.000002.50000-1.5811
58.00000010.00000-2.000000.40000-0.6325
611.00000010.00000+1.000000.10000+0.3162

The chi-square is one number for the whole table; the contributions say which category produced it. A standardised residual beyond about ±2 marks a cell worth explaining, and the test itself never names one.

What the “expected ≥ 5” rule actually buys

2,500 replications per row, every sample drawn from a genuinely uniform population. The null is TRUE, so every rejection is a false positive and a correct test sits at 5%.

Realised type-I error of the chi-square goodness-of-fit test at various expected cell counts
CategoriesSample sizeExpected per cellRealised αReading
66010.0004.44%close to nominal
6305.0004.68%close to nominal
6183.0004.52%close to nominal
6122.0002.88%conservative — power given up
10202.0004.68%close to nominal
482.0003.40%conservative — power given up

Nothing in this table is liberal. Below the floor of 5 the test becomes CONSERVATIVE — it rejects less often than 5%, not more. So breaking the rule costs power rather than inflating false positives, which is the opposite of how it is usually explained. A sparse table that comes out significant is still significant; one that does not may simply have had too little to work with.

Degrees of freedom are categories minus one, minus any parameter you estimated from the same data. Testing against a fixed set of proportions costs nothing; fitting a distribution first — a Poisson rate, a binomial probability — costs one degree of freedom per parameter, and forgetting that makes the p-value too small. The field above is where you declare it.
The test needs counts, not percentages. Feeding it percentages silently sets the sample size to 100 whatever it really was, which is the single most common way this test is misused. If your data is a set of proportions, multiply back to counts first.

What this tool shows

The “every expected count should be at least 5” rule protects against the opposite of what people think. Measured at 2,500 replications per row: at 5 expected per cell the realised type-I error is 4.35%, and at 2 it is 3.27%. Breaking the rule costs POWER; it does not inflate false positives. The tool computes the table alongside your result.

  • Chi-square against equal or unequal expected proportions, from raw weights
  • Each cell’s contribution to the statistic, so the driver is named
  • Standardised residuals, which flag the cells worth explaining
  • Degrees of freedom adjusted for any parameter you estimated
  • A measured type-I error table across six expected-count regimes
  • A flag when cells fall below the conventional floor, with what that costs
Per-cell breakdown The rule measured Any expected weights Residuals included

Counts, not percentages. The distinction changes everything.

Updated 12 September 2026 · Works in any browser, no installation

The test compares observed counts against the counts a hypothesis predicts, and sums the squared gaps scaled by what was expected. Each cell contributes (O − E)²/E, so a given discrepancy counts for more where little was expected — and the total is compared against a chi-square distribution on one fewer degree of freedom than there are categories.

At a glance

Formula shown
χ² = Σ(Oᵢ − Eᵢ)²/Eᵢ over all categories, compared against a chi-square on k − 1 degrees of freedom — minus one more for every parameter estimated from the same data. Expected counts come from the hypothesised proportions multiplied by the observed total, so raw weights work as well as probabilities. The standardised residual (Oᵢ − Eᵢ)/√Eᵢ is roughly a z-score for each cell and is what localises a significant result.
Scenario support
Testing a die or a random generator for fairness, checking whether observed frequencies match a forecast or a historical distribution, comparing a sample’s category mix against a population, and validating that counts follow a fitted Poisson or binomial.
Educational estimate
Planning support from the values you enter — not professional advice.

The “expected at least 5” rule, measured

Every textbook carries it and almost none say what it protects against. The tool simulates the answer.

Every replication draws from a genuinely uniform population, so the null is TRUE and every rejection is a false positive. A correct test sits at 5%.

At 10 expected per cell the realised error is 4.50%; at exactly 5 it is 4.35%. The approximation is behaving.

Below the floor it does not become liberal. At 3 expected per cell the rate is 4.75%, and at 2 it is 3.27% — conservative. The test rejects LESS often than advertised, not more.

So the cost of breaking the rule is power, not false positives. Which reverses the practical advice: a sparse table that comes out significant is still significant, and one that does not may simply have had too little to work with.

And it makes the standard remedy harder to justify. Pooling adjacent categories until every expectation clears 5 changes the hypothesis being tested — the pooled categories are not the ones you set out to examine — and the measured table says the problem it solves is conservatism rather than invalidity.

The rule is not worthless. It is a guard on a continuous approximation to a discrete distribution, and the discreteness is what produces the conservatism. Where an exact multinomial test is available, it removes the question entirely.

The statistic is one number; the cells say what happened

A significant chi-square says the observed counts do not match the expected ones. It never says which category is responsible, and that is almost always the finding.

On the die preset, face 3 supplies 8.10 of the 11.60 total. Seventy per cent of the statistic comes from one face; the other five contribute 3.50 between them. “The die is unfair” is a much weaker statement than “face 3 comes up far too often”.

Standardised residuals turn each cell into something like a z-score. (O − E)/√E, so a value beyond about ±2 marks a cell worth explaining. The tool highlights those.

They also carry a sign, which the contribution does not. Squaring loses the direction, so two cells can contribute equally while one is far too high and the other far too low.

Scanning residuals for the biggest one is a multiple comparison, though, and the usual fix is to require a larger threshold or apply a correction across cells. Worth knowing before reporting the largest residual as a finding.

Degrees of freedom cost one per estimated parameter

The commonest silent error in this test has nothing to do with the arithmetic.

Testing against a FIXED set of proportions costs nothing. A fair die, a published population distribution, a forecast made in advance: degrees of freedom are simply k − 1.

Fitting the distribution first costs one degree of freedom per parameter. Estimating a Poisson rate from the same counts you then test costs one; a normal’s mean and variance cost two.

Forgetting that makes the p-value too small. The reference distribution is too wide, so the tail beyond your statistic is overstated — the error always runs toward finding a difference that is not there.

The field in the tool is where you declare it, and the degrees of freedom update immediately. If you fitted anything from this data, the number is not zero.

Counts, not percentages

The single most common way this test is misused, and it produces a plausible-looking answer every time.

Feeding it percentages silently sets the sample size to 100. The statistic scales directly with n, so a genuine sample of 10,000 entered as percentages is tested as though it were a hundred observations — and a real effect vanishes.

It runs the other way too. A sample of 40 entered as percentages is tested as though it were 100, and a chance fluctuation becomes significant.

There is no way for the test to detect this, because percentages are perfectly valid counts as far as the arithmetic is concerned. The only defence is checking that the total matches the number of observations you actually have — which the tool prints.

The expected side is different. Expected values may be given as weights, proportions or percentages, because the tool rescales them to sum to 1 before multiplying by the observed total. Only the observed side has to be counts.

What a significant result does not establish

Three readings the test does not support, and one it is often used to avoid.

It does not say the departure is large. The statistic scales with n, so a trivially small discrepancy is significant on a big enough sample. The residuals and the observed-minus-expected column are where the size lives.

It does not say WHICH alternative is true. The test is omnibus: it rejects the hypothesis without proposing anything. A pattern in the residuals — a trend, a single spike, a systematic shift — is a much more useful description than the rejection itself.

A non-significant result is not a demonstration of fit. It is a failure to detect a departure, which at small n is the likely outcome whatever the truth — and the measured table shows sparse tables are conservative on top of that.

And the observations must be independent. Counting the same subject twice, or counting clustered observations as if they were separate, inflates the statistic in a way nothing in the output reveals.

Reporting a goodness-of-fit test

Four things, and the third is what makes the result useful rather than merely correct.

Report χ² with its degrees of freedom and the sample size. “χ²(5, N = 60) = 11.60, p = 0.041” is complete; a bare p-value hides both.

Say what the expected proportions were and where they came from. A hypothesis chosen after looking at the counts is not a hypothesis, and the reader cannot tell from the output.

Name the cells that drove it. The contributions and residuals are the finding; the omnibus p-value is a summary of them.

And state whether any parameter was estimated. It changes the degrees of freedom, and a reader checking your arithmetic will get a different answer without it.

Sources and methodology

References for the chi-square goodness-of-fit test.

Method. Expected counts come from the supplied weights rescaled to proportions and multiplied by the observed total, so percentages and raw weights behave identically on the expected side; the statistic is verified against a hand-summed chi-square and against the same counts in a different order. The “expected at least 5” rule is tested rather than repeated: 2,500 replications per configuration draw from a genuinely uniform population, so every rejection is a false positive, and the suite asserts that no configuration comes out liberal and that the sparse ones come out conservative — 3.27% at two expected per cell against a nominal 5%. Degrees of freedom decrement correctly per estimated parameter, and a design with none left returns no result rather than a p-value. That engine is verified on every change against 69 assertions. The count and the per-case breakdown are published on the formula verification page.

Related calculators

Where this goes next:

Chi-SquareGoodness of fit and tests of independence with every expected count and per-cell contribution shown — because the validity condition is about expected counts, not observed ones, and most calculators hide them.
Fisher's Exact TestThe exact p for a 2×2 table under all three two-sided conventions, because they disagree — 0.0406 against 0.0699 on the built-in table, across the 5% line — plus the test's actual size by enumeration, which is 2.30% at a nominal 5%.
Runs TestThe Wald-Wolfowitz test with every run boundary drawn: ten 1s then ten 0s gives z = −3.9055 and perfect alternation +3.9055 — identical counts, mirror-image results, which no frequency test can see.
Poisson DistributionPoisson probabilities with a dispersion test against your own variance — because a Poisson forces variance to equal the mean, and real count data usually does not, which is exactly where the tail goes wrong.
Binomial DistributionExact binomial probabilities at any n — including thousands, where a factorial overflows — with the normal approximation beside them and its error measured, which is 0.6% at the centre and 261% in the tail.
Frequency DistributionA frequency table with relative and cumulative columns, and all six standard bin-count rules computed at once — they disagree by a factor of 6.67 at n = 10,000, where Sturges asks for 15 bins and the square-root rule asks for 100.

More in Math, or browse all calculators.

Educational use disclaimer

An educational tool. The test assumes independent observations and a hypothesis fixed in advance — neither is visible in a table of counts, and a result computed from clustered data or from proportions chosen after the fact will look entirely normal while meaning nothing.

How we calculate · Found an error? email us

Authorship & verification

Written and maintained by , a business operator who builds spreadsheet-based calculators.

What's changed (5 updates)

Published 12 September 2026

  1. Published a chi-square goodness-of-fit tool with per-cell contributions and standardised residuals, so a significant result comes with the cells that caused it.
  2. Measured the 'expected count at least 5' rule instead of repeating it, and found the received wisdom points the wrong way: below the floor the test becomes CONSERVATIVE, rejecting only 3.27% of true nulls at 2 expected per cell, not liberal. The rule protects against a miscalibration in the opposite direction to the one usually described.
  3. Handled the degrees-of-freedom adjustment for parameters estimated from the same data, which is the difference between testing a distribution you fixed in advance and one you fitted.
  4. Made the distinction between a goodness-of-fit test and a test of independence explicit, since the same chi-square arithmetic serves both and the degrees of freedom differ.
  5. Verified against 69 assertions covering the statistic, the residuals, the calibration sweep and the boundary cases where a category has zero expected count.

Add this calculator to your site

Responsive embed — and private: nothing your visitors type leaves their browser.