Editverse Free Calculator
Chi-Square Test Calculator
Test whether two categorical variables are associated — with the exact χ² statistic, degrees of freedom, p-value, and expected counts. Enter any contingency table, see the formula and the reproducible R command, and read a full interpretation guide below. Validated against R 4.3.3.
In Simple Words
A chi-square test asks whether two yes/no or category-type variables are linked. You build a small table of counts — for example, treated vs untreated across cured vs not cured — and the test compares the counts you observed with the counts you would expect if the two variables had nothing to do with each other.
If the observed and expected counts are far apart, the p-value is small and the variables are probably associated. Use it when both variables are categorical and your table cells are reasonably large. If your sample is small (any expected count below 5), use Fisher’s exact test instead. If the same subjects are measured twice (paired yes/no), use McNemar’s test.
When to Use a Chi-Square Test
The chi-square test of independence checks whether two categorical variables are associated by comparing observed cell counts in a contingency table against the counts expected under independence. It is the standard test for questions like “is treatment group related to response?” or “does exposure differ by disease status?”
Use it when both variables are categorical, observations are independent, and the expected count in (almost) every cell is at least 5. When expected counts fall below that threshold — common in small samples or sparse 2×2 tables — the chi-square approximation breaks down and Fisher’s exact test is more appropriate. Remember that a significant chi-square tells you an association exists, not its direction or size: report an effect size and, for risk questions, the odds ratio or relative risk. Not sure this is the right test? Our interactive Test Selector walks you through the decision.
Expected format — Observed counts (rows on new lines, comma-separated)
Drop a CSV here or click to choose. Parsed in your browser — nothing is uploaded.
Expected format — Observed counts (rows on new lines, comma-separated)
tbl <- matrix(c({obs_flat}), nrow = {nrows}, byrow = TRUE)
chisq.test(tbl)User guide
When to use. Test whether two categorical variables are associated, using a contingency table of counts.
Assumptions. Expected count in each cell should be at least 5. Observations independent.
Common mistakes. If expected counts are below 5 (small samples), use Fisher’s exact test instead.
Worked example
Click Load example data above, then Run Analysis to see a fully worked result with figure, formula and interpretation for this test.
References
- Pearson K. On the criterion that a given system of deviations… Philos Mag. 1900;50:157-175.
Worked Examples
Example 1 — Treatment vs outcome (associated)
A 2×2 table records cured/not-cured by treated/untreated: treated 30 cured and 20 not; untreated 15 cured and 35 not. The cure pattern differs sharply between groups, so the χ² statistic is large and the p-value small (p < 0.01) — evidence that treatment and outcome are associated. To describe the size and direction of that association, also compute the odds ratio.
Example 2 — Small sample (use Fisher’s instead)
If the same kind of table had tiny counts — say 4, 1 / 1, 4 — one or more expected counts fall below 5, and the chi-square approximation is no longer reliable. Switch to Fisher’s exact test, which computes an exact p-value valid for small samples.
Assumptions to Check
Categorical data. Both variables must be categorical (nominal or ordinal collapsed into categories), entered as counts — not percentages or means.
Independence. Each observation contributes to exactly one cell, and observations are unrelated. Paired or repeated measures on the same subjects violate this — use McNemar’s test instead.
Adequate expected counts. The expected count should be at least 5 in (almost) every cell. When it is not, use Fisher’s exact test.
Common Mistakes
Using chi-square with small expected counts
If any expected cell count is below 5, the chi-square approximation is unreliable. Use Fisher’s exact test for small or sparse tables.
Entering percentages instead of counts
Chi-square works on raw frequencies. Convert proportions back to actual counts before running the test.
Applying it to paired data
For before/after or matched binary data on the same subjects, use McNemar’s test, not the ordinary chi-square.
Reporting significance without an effect size
A significant chi-square shows an association exists, not how strong it is. Report Cramer’s V or, for 2×2 risk questions, the odds ratio or relative risk.
Frequently Asked Questions
Chi-square or Fisher’s exact?
Use chi-square when expected counts are adequate (at least 5 in most cells) and the sample is reasonably large. Use Fisher’s exact for small samples or sparse tables.
What is the Yates continuity correction?
For 2×2 tables, the Yates correction makes the chi-square slightly more conservative. It is optional and debated; many researchers prefer Fisher’s exact for small 2×2 tables instead.
How do I report a chi-square result?
Report the statistic, degrees of freedom, and p-value, e.g. χ²(1) = 9.0, p = 0.003, alongside the counts and an effect size.
Does the result match SPSS, R, and Stata?
Yes. The calculator uses the same chi-square distribution functions as standard software and shows the exact R command so you can reproduce it.
Related Calculators
References
- Pearson K. On the criterion that a given system of deviations from the probable… Philos Mag. 1900;50(302):157–175.
- Hazra A, Gogtay N. Biostatistics Series Module 4: Comparing Groups — Categorical Variables. Indian J Dermatol. 2016;61(4):385–392. PMID 27512183.
- Greenland S, Senn SJ, Rothman KJ, et al. Statistical tests, P values, confidence intervals, and power: a guide to misinterpretations. Eur J Epidemiol. 2016;31(4):337–350. PMID 27209009.
Need This Analysis Done for Your Manuscript?
Our PhD biostatisticians build your contingency tables, choose chi-square or Fisher’s correctly, and deliver publication-ready results with reproducible R output.
Get Expert Statistical Help