Chi-Square Test Calculator
Paste a contingency table (rows of counts, one row per line) to test whether two categorical variables are associated. You get the chi-square statistic, degrees of freedom, p-value and the expected counts — matching R’s chisq.test().
▶ Watch: the same test in R — chisq.test(), the expected counts, and Fisher’s exact test for small samples.
Download the R script · ▶ Practice in the playground
The R code from the video, ready to copy:
# Chi-square & Fisher's exact test
# A 2x2 table: treatment (rows) by outcome (columns)
tbl <- matrix(c(90, 60, 30, 120), nrow = 2, byrow = TRUE)
tbl
# Chi-square test of independence
chisq.test(tbl)
# Expected counts under independence
chisq.test(tbl)$expected
# Fisher's exact test - exact, good for small samples
fisher.test(tbl)How to use it
What it tests
The chi-square test of independence compares the observed counts in your table to the counts you’d expect if the two variables were unrelated. A large chi-square (small p) means the variables are associated.
- Degrees of freedom = (rows − 1) × (columns − 1).
- The test needs reasonably large expected counts. A common rule: if any expected count is below 5, the approximation gets shaky — switch to Fisher’s exact test. This calculator warns you when that happens.
- A significant result says an association exists, not how strong it is. For strength, report an effect size such as Cramér’s V.
Do it in R
tab <- matrix(c(90, 60, 30, 120), nrow = 2, byrow = TRUE)
chisq.test(tab) # chi-square test
chisq.test(tab)$expected # expected counts
fisher.test(tab) # exact alternative for small countsSee the full walkthrough: Chi-square test of independence in R.
FAQ
Frequently asked questions
When should I use Fisher’s exact test instead?
When any expected cell count is small (a common threshold is below 5). Fisher’s exact test doesn’t rely on the large-sample approximation, so it’s the safer choice for small tables.
Does R apply a continuity correction?
For 2×2 tables, chisq.test() applies Yates’ continuity correction by default (correct = TRUE). This calculator reports the uncorrected statistic; use correct = FALSE in R to match it exactly.
A single table is rarely the whole story. When you need modelling and a written report, that’s our work.