Chi-Square Test Calculator
A chi-square test asks whether two categorical variables are related (like sex and smoking status), or whether observed counts match what you would expect by chance. Paste a 2-D table or a row of observed counts to get chi-square, the p-value, Cramer's V, standardized residuals, and a mosaic plot. Everything runs in your browser.
I want to run a on your table at α = 0.05.
New to chi-square? Read the 4-min primer
What it is. The chi-square test asks one question of a table of counts: are these counts farther from what we would expect under independence (or under a hypothesised distribution) than chance can comfortably explain? If yes, the row variable and the column variable are not independent; some cells carry a real signal.
Three flavours, one statistic. Independence takes a two-way table (e.g. treatment by outcome) and tests whether the two classifications are linked. Goodness-of-fit takes one row of counts and tests whether they match a hypothesised distribution (uniform dice, expected proportions). Homogeneity tests whether several samples share the same distribution; the math is identical to independence.
The recipe. For each cell compute the expected count under the null: E = row_total * col_total / N for independence, or E = N * p_hyp for goodness-of-fit. Sum the squared, scaled deviations: chi-square = sum (O - E)^2 / E. Compare against a chi-square distribution with df = (rows-1)(cols-1) for independence or df = k-1 for goodness-of-fit.
Beyond the p-value. A small p tells you something is off; standardised residuals tell you where. Cells with |r| > 1.96 drive the result. Cramer's V (independence) and Cohen's w (goodness-of-fit) put a magnitude on the association so you can say not just "significant" but "weak / moderate / strong".
You have a two-way table of counts and want to test whether row and column classifications are independent.
e.g. Does outcome (infected / not) depend on group (vaccine / placebo)?
tbla 2-D table of countsαsignificance level
Enter a table to see the result
Cell area is proportional to the observed count; tint to the standardised residual.
Plain-English readEnter a table above to see a plain-English verdict.
How this is computed
✓ No data leaves your browser
✓ Verified against R's chisq.test()
✓ Free, no sign-up
Anatomy of the chi-square test
One statistic, four moving parts. Here is what happens between the counts you paste and the verdict above.
qchisq(1 - alpha, df).(O - E)/sqrt(E) are easy but biased. The standardised version (matches R's chisq.test()$stdres) divides by an SE that accounts for the marginal totals; under H0 each cell is approximately N(0, 1). Cells with |r| > 1.96 drive the result.chisq.test(x, correct = FALSE)); switch it on for small 2x2 tables, or use Fisher's exact directly.When this is the wrong tool
| If you have... | Use instead |
|---|---|
| Any expected count < 5 (especially in 2x2) | Switch to Fisher's exact test - the chi-square approximation degrades when expected cells are sparse. The handoff button above adds it to the R code. |
| Paired binary outcomes (before/after on the same subject) | McNemar's test - chi-square treats rows as independent, which paired data are not. Use mcnemar.test(). |
| Ordinal categories (low / med / high) where order matters | The Cochran-Armitage trend test or a polychoric correlation. Chi-square ignores ordering and wastes power. |
| Stratified 2x2 tables (e.g. across hospitals) | Cochran-Mantel-Haenszel test - pooling strata via plain chi-square risks Simpson's paradox. |
| Continuous variables binned into categories | Do not bin first - use a t-test, ANOVA, or correlation. Binning throws away information and the p-value depends on the cut points. |
| 3+ way (multidimensional) tables | Log-linear models or hierarchical contingency analysis. Chi-square only handles two classifications cleanly. |
Frequently asked questions
When should I use chi-square versus Fisher's exact test?
Use chi-square when all expected cell counts are at least 5. Switch to Fisher's exact when any expected cell count drops below 5, the sample is small (n < 30), or you have a 2x2 table where the asymptotic approximation is unreliable. Fisher's test is also the right choice for case-control studies with rare outcomes.
How do I interpret Cramer's V from a chi-square test?
Cramer's V measures the strength of association in a contingency table, from 0 (no association) to 1 (perfect). Rules of thumb: 0.1 is small, 0.3 medium, 0.5 large. Unlike the chi-square statistic itself, V does not grow with sample size, so it tells you whether a significant result is also practically meaningful.
What does Yates' continuity correction do?
Yates' correction subtracts 0.5 from each absolute deviation in a 2x2 table before squaring, compensating for treating discrete counts as continuous. It reduces the false-positive rate but is conservative for moderate samples. R's chisq.test applies it by default; set correct = FALSE to disable. Modern practice often prefers Fisher's exact for small samples.
What is the difference between independence and homogeneity?
The arithmetic is identical: both build expected counts from the marginals and sum the scaled squared deviations. They differ in study design. Independence samples one group and cross-classifies it on two variables (are they linked?). Homogeneity samples several groups with fixed row totals and asks whether they share the same column distribution. Same chi-square, different sentence.
Does this calculator match R?
Yes. The chi-square statistic, degrees of freedom and p-value match R's chisq.test(), the standardised residuals match chisq.test()$stdres, and Cramer's V matches rcompanion::cramerV(). The math is verified against R 4.6.0 across every mode and edge case.
Go deeper
Numerical accuracy: chi-square, df, and p match R's chisq.test() to at least 4 decimals; standardised residuals match chisq.test()$stdres; Cramer's V matches rcompanion::cramerV().