SCIENCE & MATHS

Chi-Square Test

Chi-square test of independence on a contingency table or goodness of fit against expected counts — χ², degrees of freedom, p-value, critical value, Cramér’s V.

χ², df, the p-value and the critical value at your α, Cramér’s V for tables, expected counts and each cell’s contribution, and a flag for expected counts below 5.

Example: Table [10 20 / 30 40] → expected [12 18 / 28 42], χ² = 0.794 on 1 df, p = 0.373, Cramér’s V 0.089: no evidence of association. Counts 25/30/45 vs equal → χ² = 6.5, p = 0.039.

v0.1.0 · last reviewed 21 September 2026
Loading the workspace…
BUILT TO BE UNDERSTOOD

Observed against
expected.

How expected counts are built, where the p-value comes from, and when the test is unreliable.

Two questions

Independence: are two categorical variables associated? The expected count in each cell of the table is row total × column total ÷ N — what you would see if the rows and columns were unrelated — and χ² = Σ(O − E)²/E on (rows − 1)(columns − 1) degrees of freedom. Goodness of fit: do observed counts match expected proportions? The same sum on k − 1 degrees of freedom.

The p-value

Under the null hypothesis χ² follows the chi-square distribution; the p-value is its upper tail Q(df/2, χ²/2), computed from the regularized incomplete gamma function (series for small arguments, a continued fraction otherwise). The critical value at your α is found by bisection on the same function. Cramér’s V = √(χ² ÷ (N·min(r − 1, c − 1))) scales the association to 0–1.

Limits

The approximation needs expected counts of about 5 or more per cell — smaller ones are flagged; Fisher’s exact test or pooling categories is the usual remedy. Yates’ correction (|O − E| − 0.5) is offered for 2 × 2 tables and is conservative. Counts must be independent observations, not repeated measures. Nothing leaves the browser; the same four anonymous usage counts as the rest of the site apply.

SOURCES

  • χ² = Σ(O − E)²/E; expected = row × column ÷ N; df = (r − 1)(c − 1) or k − 1; p = Q(df/2, χ²/2) via the regularized incomplete gamma function; optional Yates correction for 2 × 2

Last reviewed 21 September 2026. How results are checked: How we verify.