Skip to content

Chi-Square Test Calculator

Paste a contingency table of counts and get the chi-square statistic, its degrees of freedom, the p-value, the critical value and the smallest expected count.

χ²

19.177972

3 × 4 table, 309 observations in all

Degrees of freedom

6

(rows − 1) × (columns − 1)

p-value

0.0038733888

the share of tables at least this far from independence, if the two classifications really are independent

Critical value at 0.05

12.591587

reject independence when χ² lands above this

Smallest expected count

11.559871

at or above 5, the usual rule of thumb for trusting the approximation

Ê(n_ij) = r_i · c_j / n · χ² = Σ (n_ij − Ê(n_ij))² / Ê(n_ij) · df = (r − 1)(c − 1)

A chi-square test of independence asks whether two ways of sorting the same things are related. Sort wafers by defect and by shift, students by course and by grade, visitors by page and by whether they bought: if the proportions look the same across every row, the two classifications are independent. This page compares the counts you actually saw against the counts independence would predict, and turns the gap into a statistic and a p-value. It also shows the smallest predicted count, because that single number decides whether the p-value means anything at all.

How it is calculated

Ê(n_ij) = r_i · c_j / n · χ² = Σ (n_ij − Ê(n_ij))² / Ê(n_ij) · df = (r − 1)(c − 1)

If the two classifications were independent, the chance of landing in a given cell would be the row chance times the column chance, so the expected count is the row total times the column total over the grand total. The statistic adds up how far each cell is from that, squared, scaled by how big the cell was expected to be — which is why a gap of five matters far more in a cell expecting six than in one expecting six hundred. The degrees of freedom count the cells you could still fill in freely once every row and column total is fixed.

Source: NIST/SEMATECH e-Handbook of Statistical Methods, 7.4.5, How can we compare the results of classifying according to several categories? — the wafer-defect table 15 21 45 13 / 26 31 34 5 / 33 17 49 20 over 309 defects gives expected frequencies of 22.51 20.99 38.94 11.56 / 22.9 21.44 39.77 11.81 / 28.50 26.57 49.29 14.63 and a test statistic of 19.18 on (3−1)(4−1) = 6 degrees of freedom

Questions people ask

What does a small p-value tell me here?
That the counts are further from independence than chance comfortably explains — and nothing more. It does not say which cells are responsible, how strong the association is, or which way the causation runs. A table with thousands of observations will hand you a tiny p-value for an association too weak to act on, because the test measures evidence against independence, not the size of the departure from it. Look at the observed counts beside the expected ones to see where the departure actually is.
Why does the smallest expected count matter?
Because chi-square is an approximation. The statistic only follows the chi-square distribution when the counts in each cell are big enough for a normal approximation to hold, and the long-standing rule of thumb is that every expected count should be at least five. Below that the p-value tends to come out smaller than it should be, so the test flags associations that are not there. The usual repairs are to merge sparse categories into a meaningful larger one, or to use an exact test.
Should I be using Fisher's exact test instead?
Probably, if you have a two-by-two table with small counts. Fisher's test computes the probability directly from the hypergeometric distribution rather than approximating it, so it stays honest where chi-square drifts. This page does not offer it, because we build from a published source and the NIST/SEMATECH handbook this family is written against does not cover it.
Do I need equal numbers in each row?
No. The expected counts are built from your own row and column totals, so unequal rows are the normal case rather than a problem. What the test does require is that every observation falls into exactly one cell and that the observations are independent of one another — so counting the same person twice, or counting repeated visits from one visitor as separate observations, breaks it in a way no arithmetic will notice.
What counts as a row and a column?
One line of numbers is one row; the numbers within a line are the columns. Separate them with spaces, commas or semicolons, whichever your data came with. Every line has to have the same number of entries, and anything that does not read as a number is skipped rather than treated as zero — so a pasted header row will make the table ragged rather than quietly shifting your counts.
Is this the same as a goodness-of-fit test?
No. This page tests two classifications against each other using expected counts derived from the table itself. A goodness-of-fit test compares one set of counts against proportions you specify in advance, and its degrees of freedom are counted differently. The arithmetic in the middle looks identical, which is exactly why the two get confused.

Sources

The documents this page reads its numbers out of, linked so you can check them yourself.

  1. NIST/SEMATECH e-Handbook of Statistical Methods, 7.4.5, How can we compare the results of classifying according to several categories? — the wafer-defect table 15 21 45 13 / 26 31 34 5 / 33 17 49 20 over 309 defects gives expected frequencies of 22.51 20.99 38.94 11.56 / 22.9 21.44 39.77 11.81 / 28.50 26.57 49.29 14.63 and a test statistic of 19.18 on (3−1)(4−1) = 6 degrees of freedom
  2. NIST/SEMATECH e-Handbook of Statistical Methods, 1.3.6.7.4, Critical Values of the Chi-Square Distribution — upper-tail critical values: row 1 gives 2.706 at column 0.90 and 6.635 at column 0.99, and row 6 gives 14.449 at column 0.975

Related tools

Found a problem, or want more?

A number that disagrees with its source is a defect, not a rounding preference.

What did you enter, what did the tool show, and what did you expect instead? If you have a source that disagrees with ours, a link to it is the most useful thing you can send.

Write to us

Opens your mail app with the page and tool already filled in.