Chi-Square Test Calculator

Run a chi-square goodness-of-fit or independence test — the statistic, degrees of freedom, p-value and the decision at your significance level.

How to use this calculator

  1. 1Choose goodness of fit (one set of categories against an expectation) or independence (a contingency table of two variables).
  2. 2Enter the observed counts. For goodness of fit, leave expected counts blank to test against a uniform distribution.
  3. 3Compare the p-value against your significance level — and check the smallest expected count, since the test is unreliable below about 5.

How the calculation works

χ² = Σ (O − E)² / E
O
Observed count in a cell
E
Expected count under the null hypothesis
df
Degrees of freedom — (categories − 1), or (rows − 1)(columns − 1) for a contingency table

Each cell contributes its squared deviation scaled by how large a deviation was expected there. Dividing by E is what makes a difference of 10 matter enormously when 5 was expected and barely at all when 5,000 was.

For an independence test the expected count in each cell is (row total × column total) ÷ grand total — what you would see if the two variables were completely unrelated.

The p-value is the upper-tail probability of the chi-square distribution, computed here from the regularized incomplete gamma function: p = 1 − P(df/2, χ²/2).

Worked example

Are six categories uniformly distributed?

  1. 1.Total observations: 30 + 14 + 34 + 45 + 57 + 20 = 200, so a uniform expectation is 200 ÷ 6 = 33.3333 per category.
  2. 2.Each cell contributes (O − E)² ÷ E — for example the first: (30 − 33.3333)² ÷ 33.3333 = 11.1111 ÷ 33.3333 = 0.3333.
  3. 3.The six contributions are 0.3333, 11.2133, 0.0133, 4.0833, 16.8033 and 5.3333, which sum to χ² = 37.78.
  4. 4.Degrees of freedom: 6 categories − 1 = 5.
  5. 5.The upper-tail probability of χ² = 37.78 with df = 5 is about 4.2 × 10⁻⁷ — far below 0.05, so the uniform hypothesis is rejected decisively. The 57 and the 14 are doing most of the work, contributing over 28 of the 37.78 between them.

Result: χ² = 37.78, df = 5, p ≈ 0.00000042 — significant

What the test actually asks

A chi-square test compares counts you observed against counts you would expect if some specific hypothesis were true, and asks whether the gap between them is larger than random variation would comfortably produce. It works on frequencies — how many things fell into each category — not on measurements like heights or temperatures, which is the most common misuse.

The statistic itself is a sum of scaled squared deviations. Squaring means over- and under-shoots both count as evidence against the hypothesis rather than cancelling out; dividing each by its expected value is what puts them on a common scale, so that being 10 off when you expected 5 registers as a much bigger surprise than being 10 off when you expected 5,000.

The two common variants

Both use the identical formula; they differ in where the expected counts come from and how degrees of freedom are counted.

  • Goodness of fitcompares one categorical variable against a stated distribution — is this die fair, do these blood types match population proportions, are sales evenly spread across weekdays. Degrees of freedom is (categories − 1).
  • Test of independencetakes a contingency table of two categorical variables and asks whether they are related. Expected counts come from the row and column totals themselves, under the assumption of no relationship. Degrees of freedom is (rows − 1) × (columns − 1).

The expected-count-of-5 rule

The chi-square statistic does not actually follow a chi-square distribution — it approximates one, and the quality of that approximation depends on the expected counts being reasonably large. The widely used rule of thumb is that every expected count should be at least 5, with some texts relaxing this to allowing a minority of cells below 5 provided none is below 1.

When expected counts are too small the p-value becomes unreliable, typically overstating significance. The standard remedies are to combine sparse categories into a broader one, collect more data, or switch to Fisher's exact test, which computes the probability directly rather than approximating it. This calculator flags the smallest expected count for exactly this reason.

What a significant result does and does not mean

Rejecting the null hypothesis says the observed pattern is unlikely under that hypothesis. It does not say the effect is large, important, or causal. With a big enough sample, trivially small departures become statistically significant, which is why a significant chi-square should always be read alongside the cell-by-cell contributions to see where the deviation actually is and how big it is in practical terms.

The reverse error matters too. Failing to reject is not evidence that the null hypothesis is true — it means this data did not provide enough evidence against it, which can equally reflect a small sample as a genuine absence of effect.

What this assumes, and where it stops

Assumptions

  • The data are counts of independent observations, each falling into exactly one category.
  • Observations are independent — the same subject counted twice, or repeated measures on the same individuals, violates this.
  • Expected counts are large enough (conventionally at least 5 in every cell) for the chi-square approximation to hold.

Limitations

  • Works on frequencies only. Percentages, proportions or continuous measurements must not be entered directly — convert to raw counts first.
  • Does not apply Yates' continuity correction for 2 × 2 tables, which some texts recommend and which yields a slightly more conservative result.
  • Detects that a relationship exists, not its direction, size or cause. Read the cell contributions to see where the deviation lies.

Common questions

Can I use percentages instead of counts?

No — this is the most common error with chi-square. The test relies on actual frequencies because sample size is what determines how surprising a deviation is. Entering percentages effectively tells the test your sample size was 100 regardless of what it really was, which distorts the statistic and the p-value.

What if some expected counts are below 5?

The chi-square approximation degrades and the p-value becomes unreliable, usually in the direction of overstating significance. Combine sparse categories into a broader one, gather more data, or use Fisher's exact test, which calculates the probability exactly rather than approximating.

What is the difference between goodness of fit and independence?

Goodness of fit tests one variable against an expected distribution you supply (or a uniform one). Independence tests whether two variables in a contingency table are related, deriving the expected counts from the row and column totals. The formula is the same; the degrees of freedom differ.

Formula and content last reviewed on .

Results are estimates for information only, not professional advice.

Report an error

Tools people commonly use alongside the chi-square test calculator.

See all statistics calculators →