Chi-Square Calculator
Goodness-of-fit and independence tests with expected counts, chi-square statistic, and p-value.
Expected counts
| 83.76 | 76.78 | 108.19 | 80.27 |
| 36.24 | 33.22 | 46.81 | 34.73 |
Use a chi-square test when your data are counts in categories. Two flavours: goodness-of-fit asks whether one set of observed counts matches an expected distribution; the test of independence asks whether two categorical variables in a contingency table are related.
The two chi-square tests
Goodness-of-fit — compare observed counts in c categories against a theoretical distribution. df = c − 1.
Test of independence — observed counts in an r × c contingency table. Tests H₀: rows and columns are independent. Expected count for cell (i, j) = (row total · column total) / grand total. df = (r − 1)(c − 1).
Both compute χ² = Σ (O − E)² / E and compare against a chi-square distribution. Larger χ² = bigger gap between observed and expected.
Assumptions and conditions
Independent observations: each subject counted once, no repeated measures on the same individual within the table.
Random sampling from the population of interest.
Expected counts ≥ 5 in at least 80% of cells, and no cell with expected < 1. If violated, combine adjacent categories or use Fisher's exact test for small 2×2 tables.
Categories must be mutually exclusive and exhaustive — every observation belongs to exactly one cell.
Worked example — goodness-of-fit
Roll a die 60 times, observe (12, 8, 11, 9, 10, 10). Is it fair? Under H₀, each face is expected 10 times.
χ² = (12−10)²/10 + (8−10)²/10 + (11−10)²/10 + (9−10)²/10 + 0 + 0 = 0.4 + 0.4 + 0.1 + 0.1 = 1.0. df = 5.
p = P(χ²₅ ≥ 1.0) ≈ 0.96 — totally consistent with a fair die.
Worked example — independence
Survey 349 people about coffee preference (regular/decaf) vs age group (18-34, 35-54, 55+). Observed counts form a 2×3 table.
Compute expected counts from row and column marginals. If all expected counts are large and observed counts close to expected, χ² will be small and you'll fail to reject 'no association.'
If you reject, examine the (O − E)² / E contributions per cell to see which cells drive the association — those are the 'where it matters' story behind the test.
Common pitfalls
Using chi-square on percentages or proportions. The test needs raw counts; convert back to counts before testing.
Comparing a tiny table with a tiny sample. Small expected counts inflate (O − E)² / E and break the chi-square approximation.
Treating significance as effect size. A huge sample can make trivial differences 'significant'. Report Cramér's V or odds ratios for effect magnitude.
Drawing causal conclusions. A significant independence test means 'they're related,' not 'one causes the other.'
Chi-square alternatives and when to use them
Fisher's exact test is the classic alternative for 2×2 tables with small expected counts. It computes the exact probability of the observed table (and more extreme ones) under the hypergeometric distribution, avoiding the chi-square approximation entirely.
G-test (likelihood-ratio test) is asymptotically equivalent to chi-square but handles sparse tables better and has nicer theoretical properties for log-linear models. Most software reports both χ² and G for large tables.
McNemar's test is for paired categorical data — before/after studies on the same subjects, or matched case-control designs. It looks only at the discordant pairs (changed responses) and ignores the concordant ones.
For ordered categories (mild, moderate, severe), the chi-square test of independence wastes information by treating order as nominal. Use the Cochran-Armitage trend test or ordinal logistic regression instead.
Frequently asked questions
What's the difference between χ² and Fisher's exact test?
Both test the same hypothesis. Fisher's is exact (no approximation) and preferred for 2×2 tables with small counts; χ² is faster and standard for larger tables.
Can I use this for a 2×2 table?
Yes. With small counts (any expected < 5), Fisher's exact is more accurate.
How do I report effect size?
Cramér's V = √(χ² / (n · min(r−1, c−1))). 0.1 small, 0.3 medium, 0.5 large.
What if my expected counts are too small?
Combine adjacent categories, drop very sparse rows/columns, or switch to Fisher's exact.
More in Statistics & Probability
From z-scores and confidence intervals to t-tests, chi-square, correlation, regression, and the binomial/Poisson distributions — textbook-grade tools with worked examples.
- Z-Score Calculator
Convert a value to a z-score, percentile, and tail probabilities using the standard normal distribution.
- Normal Distribution Calculator
Find P(X<x), P(X>x), and between-range probabilities for any normal distribution with mean μ and SD σ.
- Binomial Distribution Calculator
Compute P(X=k), cumulative probabilities, mean, and variance for n trials with success probability p.
- Poisson Distribution Calculator
Model rare events with rate λ — get P(X=k), cumulative probability, mean, and variance.
- Permutations & Combinations Calculator
Compute nPr (order matters) and nCr (order doesn't) with full counting-principle explanation.
- Bayes' Theorem Calculator
Update prior beliefs with new evidence using Bayes' rule — posterior probability with tree diagram.
Related calculators
Browse all Education →T-Test Calculator
One-sample and two-sample t-tests with t-statistic, p-value, and rejection regions.
Percentage Increase / Decrease Calculator
Percent change between any old and new value, with the formula and direction shown.
Bayes' Theorem Calculator
Update prior beliefs with new evidence using Bayes' rule — posterior probability with tree diagram.
Linear Regression Calculator
Least-squares slope, intercept, R², and predictions for any paired (x, y) data.
Fraction Calculator
Add, subtract, multiply, and divide fractions and mixed numbers — results returned simplified, as a mixed number, and as a decimal.
Standard Deviation Calculator
Mean, median, mode, range, sample/population standard deviation, variance, quartiles, IQR, and SEM for any list of numbers.
Course Grade Calculator
Weighted course grade from assignments, quizzes, and exams. Shows current grade plus the score needed on remaining work.
Scientific Calculator
Free online scientific calculator with trig, logs, exponents, square roots, parentheses, and constants pi and e.