Learn to calculate by playing with Chi-square calculator
A short game to see where the result comes from. Pick a language and start; you can stop halfway and come back.
Loading the game…
← Back to Chi-square calculator
What you will practise
Chi-square test for contingency tables and goodness of fit, with Cramér’s V, residuals, Yates’ correction and Fisher’s exact test.
How it works
For each cell it works out how many cases you would expect if the variables were independent (row total × column total ÷ N) and adds up the squared difference between observed and expected, divided by expected. The larger that χ², the further the data are from independence.
The p value comes from the chi-square distribution with (rows − 1) × (columns − 1) degrees of freedom. Because χ² grows with sample size, the effect size (Cramér’s V, or Cohen’s w for goodness of fit) tells you whether the difference is large or merely detectable.
Formula
Expected = (row total × column total) / N
χ² = Σ (observed − expected)² / expected
df = (rows − 1) × (columns − 1) [goodness of fit: categories − 1]
Cramér’s V = √( χ² / (N · min(rows − 1, columns − 1)) )
Cohen’s w (goodness of fit) = √( χ² / N )
Yates (2×2): χ² = Σ (|observed − expected| − 0.5)² / expected
Adjusted standardised residual = (O − E) / √( E · (1 − row/N) · (1 − column/N) )
Odds ratio (2×2) = (a·d) / (b·c); 95% CI = exp( ln(OR) ± 1.96 · √(1/a + 1/b + 1/c + 1/d) )
Worked example
Example 1. A new treatment against the usual one (2×2 table).
Treatment A: 30 improve and 20 do not. Treatment B: 15 improve and 35 do not. 22.5 were expected per cell. χ²(1) = 9.09, p = .0026; with Yates, χ² = 7.92 (p = .0049); Fisher’s exact test, p = .0046. Cramér’s V = .30 (medium effect). The odds ratio is 3.5 (95% CI 1.53 to 8.01): improvement has about three and a half times the odds with A.
Example 2. Education and income (3×3 table).
With rows 45 20 10 / 25 40 30 / 10 30 60 (N = 270): χ²(4) = 66.61, p < .001, V = .35. The residuals show where the association lies: +6.8 for “low education, low income” and +6.0 for “high with high”, −5.0 and −5.4 in the opposite corners.
Example 3. Few data: the lady tasting tea (Fisher, 1935).
Someone tastes 8 cups and gets 3 of the 4 where milk went in first and 3 of the 4 where tea went in first: table 3 1 / 1 3. Chi-square gives p = .157, but the minimum expected frequency is 2, so it is unreliable. Fisher’s exact test gives p = .486: with so little data, getting this many right proves nothing.
Example 4. Goodness of fit: Mendel’s plants.
Mendel got 315, 108, 101 and 32 plants in the four classes; theory predicts 9:3:3:1. With N = 556: χ²(3) = 0.470, p = .925, w = 0.03. The data are entirely consistent with the expected ratio.
How to play
First pick your language. Then work through the challenges one by one: each sets out a case with real numbers and, if you get stuck, you can ask for a hint. When you answer, you see whether you got it right and why. Progress is saved only in your browser, so you can stop halfway and carry on another day.