Calculator Uni

Chi-Square Calculator

Chi-square goodness of fit or a 2 × 2 test of independence, with p-value.

Quick answer

Chi-square sums (observed − expected)² ÷ expected across every category. Degrees of freedom are categories minus one for goodness of fit, or (rows − 1) × (columns − 1) for a test of independence. Every expected count should be at least 5, or the approximation fails and Fisher's exact test is needed instead.

Observed data

Chi-square statistic

5

p = 0.0821 with 2 df

Degrees of freedom

2

p-value

0.0821

Result

Not significant at 0.05

Total observations

100

All expected counts are 5 or more, so the chi-square approximation is sound.

Comparing counts to expectations

Chi-square works on frequencies, not means. For each cell you take the observed count minus the expected count, square it, and divide by the expected count; summing those gives the statistic. Squaring makes every deviation positive, and dividing by the expected count scales it — being 10 off when you expected 20 matters far more than being 10 off when you expected 1,000.

Worked example: 50, 30, 20 against 40, 40, 20

The deviations are +10, −10, and 0. Each of the first two contributes 100 ÷ 40 = 2.5, and the third contributes nothing, so chi-square is 5.0 on 2 degrees of freedom. That gives p = 0.0821 — not significant at the 0.05 level, despite one category being 25% above expectation. With only 100 observations, a gap that size is not yet hard to explain by chance.

Goodness of fit vs. independence

A goodness-of-fit test compares one set of counts against a theoretical distribution, with degrees of freedom equal to categories minus one. A test of independence asks whether two categorical variables are related, using a contingency table, with degrees of freedom of (rows − 1) × (columns − 1) — so just 1 for a 2 × 2 table. Same statistic, different question and different degrees of freedom.

The expected-count rule

The chi-square distribution is a continuous approximation to a discrete problem, and it only holds when the counts are reasonably large. The standard requirement is that every expected count is at least 5; some texts allow a single cell down to 1 provided no more than 20% fall below 5. Below that, use Fisher's exact test, which computes the probability directly rather than approximating it.

What it can and cannot tell you

A significant result says the observed pattern is unlikely under independence — it does not say how strong the association is or which direction it runs. For that, inspect the individual cell contributions and report an effect size such as Cramér's V or an odds ratio. And because the statistic grows with sample size, a very large table will flag trivial departures as significant, so always look at the size of the deviations, not just the p-value.

Frequently asked questions

How do you calculate a chi-square statistic?
For each category, subtract the expected count from the observed count, square the result, and divide by the expected count; then add those values together. For observed 50, 30, 20 against expected 40, 40, 20, that's 2.5 + 2.5 + 0 = 5.0.
What are the degrees of freedom for a chi-square test?
For goodness of fit it's the number of categories minus one. For a test of independence it's (rows − 1) × (columns − 1), so a 2 × 2 contingency table has just 1 degree of freedom.
What is the minimum expected count for a chi-square test?
Five in every cell is the standard requirement. Some texts allow one cell as low as 1 provided fewer than 20% of cells fall below 5. Below that the approximation breaks down and Fisher's exact test is the correct alternative.
What does a significant chi-square result mean?
That the observed counts are unlikely to have arisen if the variables were independent, or if the theoretical distribution were correct. It doesn't tell you how strong the relationship is or its direction — for that, examine the cell contributions and report Cramér's V or an odds ratio.

Related calculators