Chi-Square and Residual Map

Change cell counts and watch significance and residual hotspots update immediately.

Loading interactive simulation...

The residuals say which cell broke the fit 🖖

A chi-square total is one number for a whole table and it does not say where the misfit is. The residual map does. Load Strong association: χ² is 24.3415 on 2 degrees of freedom, and the largest single contributor is row 1, column 1 — 20 observed against 11.20 expected, worth 6.91 of that total. The test also assumes every expected count is at least about 5. Load Sparse and not one of the nine is. The smallest is 0.13, that one cell supplies 65% of the statistic, and the p-value still reads a tempting 0.0521.

Where the association actually lives 🖖

A single chi-square number and its p-value only tell you whether two categorical variables are linked at all — a yes-or-no verdict. The real story sits in the standardized residual map: each colored cell shows which specific combinations occur far more or far less often than independence would predict. A positive residual marks an over-represented pairing; a negative one marks an under-represented one. Chase the brightest cells, not the largest raw counts.

Fisher's fix that Pearson refused 🖖

The degrees of freedom shown here, (r−1)(c−1), come from a bitter statistical feud. Karl Pearson introduced the chi-square test in 1900 but derived its degrees of freedom from the raw category count. In 1922 Ronald Fisher showed that every expected count estimated from the table's own margins costs one degree of freedom — which is why an r×c table has (r−1)(c−1), not rc−1. Pearson dismissed the correction for the rest of his life, yet Fisher was right, and it is the formula every table here uses.

CHI-SQUARE — IS THERE AN ASSOCIATION, AND IS THE TEST EVEN VALID?

Which Chi-Square Case Are You In?

The test compares what you observed against what independence would have produced: expected = row total × column total ÷ grand total. The statistic adds up the squared gaps, and the standardized residuals say which cells drove it. Two questions have to be answered in order — first whether the expected counts are large enough for the test to mean anything, and only then whether the association is real.

Perfect independence — the statistic is exactly zero E = RiCj/n
A small χ² — the pattern is within what chance produces χ² < χ²α
A large χ² — and the residuals name the cells responsible r = (O − E)/√E
Expected counts too small — the test does not apply E ≥ 5

01

Perfect independence — the statistic is exactly zero

What you know: Every cell matches its expected count, so every residual is zero and χ² is zero with it. The rows tell you nothing about the columns.

Statistic: E = RiCj/n

Worked example: A 3×3 table of nines, all cells 8: every expected count is also 8, χ² = 0 on 4 degrees of freedom, p = 1.000

Open this case: Balanced baseline
Perfect independence — the statistic is exactly zero. Every observed count equals its expected count, so no cell contributes anything. Every cell matches its expected count, so every residual is zero and χ² is zero with it. The rows tell you nothing about the columns.
Every observed count equals its expected count, so no cell contributes anything.

02

A small χ² — the pattern is within what chance produces

What you know: The counts differ from their expected values, but not by more than sampling noise would give. χ² stays below the critical value and the residuals are all small.

Statistic: χ² < χ²α

Worked example: A 2×3 table of 60 observations → χ² = 2.594 on 2 degrees of freedom, p = 0.273. The largest standardized residual is −0.90.

Open this case: Weak dependence
A small χ² — the pattern is within what chance produces. The cells drift a little from expectation, but no single one stands out. The counts differ from their expected values, but not by more than sampling noise would give. χ² stays below the critical value and the residuals are all small.
The cells drift a little from expectation, but no single one stands out.

03

A large χ² — and the residuals name the cells responsible

What you know: The statistic clears the critical value comfortably. What matters next is not the p value but which cells produced it, and the residual table answers that directly.

Statistic: r = (O − E)/√E

Worked example: The same 2×3 shape with 60 observations → χ² = 24.342 on 2 degrees of freedom, p = 0.000005, with a standardized residual of +2.63 in the largest cell

Open this case: Strong association
A large χ² — and the residuals name the cells responsible. Two cells sit far above expectation and two far below — the association has a direction. The statistic clears the critical value comfortably. What matters next is not the p value but which cells produced it, and the residual table answers that directly.
Two cells sit far above expectation and two far below — the association has a direction.

04

Expected counts too small — the test does not apply

What you know: Chi-square is an approximation that needs reasonably large expected counts. When they are tiny, the p value it reports is not trustworthy, whatever it says.

Statistic: E ≥ 5

Worked example: A 3×3 table of only 8 observations → every one of the 9 expected counts is below 5, the smallest being 0.13. χ² = 9.389 gives p = 0.052, and that number should not be used.

Open this case: Sparse warning case
Expected counts too small — the test does not apply. Nine cells, eight observations: the expected counts are far too small to approximate. Chi-square is an approximation that needs reasonably large expected counts. When they are tiny, the p value it reports is not trustworthy, whatever it says.
Nine cells, eight observations: the expected counts are far too small to approximate.
References (2)

Problem solved in full

  1. The whole test and p-value for a 2×3 table by hand 5 steps

    A 2×3 table gives χ² = 2.5943 on 2 degrees of freedom, and a p-value of 0.2733. Work out the whole test by hand — including the p-value, which for this many degrees of freedom needs no table at all.

    1. Expected counts assume the two variables are independent, so each cell is its row total times its column total over the grand total. The smallest is 8.5, comfortably above the rule-of-thumb 5 below which the approximation is unreliable.

    2. Each cell contributes its squared deviation divided by its expectation. Dividing by E is what turns an absolute discrepancy into a comparable one — being 3 out of 11 matters more than being 3 out of 1100.

    3. The degrees of freedom count the cells you are free to fill once the margins are fixed. With the row and column totals given, choosing two cells determines the rest.

    4. Two degrees of freedom is the special case: the chi-square distribution is then just an exponential, and the p-value is e raised to minus half the statistic. No table, no software.

    5. Looking at where the statistic came from is more informative than the total. The middle column supplies 63.1% of it — the 8-against-11 and 14-against-11 cells — so if anything is going on, it is there.

    Answer

    The tool prints χ² = 2.5943, df = 2, p = 0.2733 and a minimum expected count of 8.5. A p of 0.27 is no evidence of association, and the honest reading stops there — it is not evidence of independence either, since a table of 60 observations can hide a modest effect easily. The useful habit is the last step: a chi-square total tells you almost nothing on its own, and the per-cell contributions tell you where to look. Click the strong preset and watch the middle column drop out while the four corner cells carry 99.5% of the sum.

Learning path

When is a difference real?

Leads to Sample size the same partition where there is nothing to average, only counts in categories.

Example problems

  • Weak dependence - chi² = 2.5943 on 2 degrees of freedom gives p = 0.2733, and the biggest standardised residual is -0.905. Nothing here departs from independence at all.
  • Strong association - chi² = 24.3415 on 2 degrees of freedom, p below 0.00001. The largest single cell is row 1, column 1: 20 observed where independence predicts 11.20, a residual of +2.63.
  • Sparse warning case - p = 0.0521, a whisker from significance and worth nothing. All nine expected counts are under 5, the smallest is 0.13, and that one cell supplies 65% of the statistic.
  • Balanced baseline - Every cell holds 8, so every expected count is 8, every residual is 0 and chi² is exactly 0 with p = 1. The only perfect fit on the tool.