Skip to content

Chi-Square Test Calculator

Type your counts into the table to test whether the rows and columns are linked. You get the expected counts, χ², the degrees of freedom, the p-value and a plain-English verdict. Advanced adds goodness of fit, Yates’ correction, Fisher’s exact test, effect sizes and the residuals that show which cells drive the result.

Goodness of fit, Yates, Fisher’s exact, residuals, α
Which test?
Your counts (click a name to rename it; paste from a spreadsheet)Rows2Columns3
Expected pattern
Categories (paste a column of numbers to fill down)6
Significance level (α)
Yates’ continuity correction (2 × 2 tables only)
ResultUpdates as you type—p-value—Chi-square (χ²)—Degrees of freedom—Cramér’s V

How your chi-square test is worked out

Your numbers, step by step: the totals, the counts you would expect if nothing were going on, how far off your counts are, then the p-value.

  1. 1

    Add up the totals

    2 × 3 table, N = 120

  2. 2

    Expected counts

    60 × 50 ÷ 120 = 25

  3. 3

    Add up (O − E)² ÷ E

    χ² = 8

  4. 4

    The p-value

    df 2 → p = 0.0183

Read more: the formula, a worked example, when to use Fisher’s test, and what the result does and doesn’t mean

A chi-square (χ², said “kai-square”) test compares the counts you saw with the counts you would expect if nothing interesting were going on. For a table, “nothing going on” means the rows and columns are unrelated, so every row splits across the columns in the same proportions as the whole table. The further your counts are from those expected counts, the bigger χ² gets, and the less likely the gap is just chance.

The formula

Expected count for a cell: E = row total × column total ÷ grand total
χ² = sum over every cell of (observed − expected)² ÷ expected
Degrees of freedom (table) = (rows − 1) × (columns − 1)
Goodness of fit: E = total × expected share; df = categories − 1 − parameters estimated
p-value = P(χ² with df degrees of freedom ≥ your χ²)
Yates (2 × 2): χ² = sum of (|observed − expected| − 0.5)² ÷ expected
Cramér’s V = √(χ² ÷ (N × (smaller of rows, columns − 1))); phi (2 × 2) = (ad − bc) ÷ √(row1 × row2 × col1 × col2)
Adjusted residual = (observed − expected) ÷ √(expected × (1 − row total ÷ N) × (1 − column total ÷ N))
G-test: G = 2 × sum of observed × ln(observed ÷ expected)

In words: work out what each cell would hold if the rows and columns had nothing to do with each other, see how far off each real count is (squared, and scaled by the expected count), and add those up. The p-value is the share of the chi-square distribution with your degrees of freedom that lies at your χ² or further out. If p is below α, the result is called statistically significant.

Worked example

Drinks chosen by shift. Morning: tea 20, coffee 30, juice 10. Evening: tea 30, coffee 15, juice 15. α = 0.05.

  • Totals: Morning 60, Evening 60; tea 50, coffee 45, juice 25; grand total N = 120.
  • Expected counts: tea 60 × 50 ÷ 120 = 25, coffee 60 × 45 ÷ 120 = 22.5, juice 60 × 25 ÷ 120 = 12.5, the same for both shifts because both rows total 60.
  • Morning: (20 − 25)² ÷ 25 = 25 ÷ 25 = 1; (30 − 22.5)² ÷ 22.5 = 56.25 ÷ 22.5 = 2.5; (10 − 12.5)² ÷ 12.5 = 6.25 ÷ 12.5 = 0.5.
  • Evening: (30 − 25)² ÷ 25 = 1; (15 − 22.5)² ÷ 22.5 = 2.5; (15 − 12.5)² ÷ 12.5 = 0.5.
  • χ² = 1 + 2.5 + 0.5 + 1 + 2.5 + 0.5 = 8, with df = (2 − 1) × (3 − 1) = 2.
  • With 2 degrees of freedom the chi-square tail is exactly e−χ²/2, so p = e−4 = 0.018316. The critical value at α = 0.05 is −2 × ln 0.05 = 5.991465, and 8 is beyond it, so the result is statistically significant at the 5% level.
  • Cramér’s V = √(8 ÷ (120 × 1)) = √0.066667 = 0.2582, a small link by Cohen’s guide (0.1 small, 0.3 medium for a table with 2 rows).
  • Adjusted residuals: coffee 7.5 ÷ √(22.5 × 0.5 × 0.625) = 7.5 ÷ 2.651650 = ±2.8284 (more coffee in the morning, less in the evening), tea ∓1.8516, juice ∓1.1239. Only coffee is beyond ±1.96, so the coffee split drives the result.
  • Every expected count is at least 12.5, so the rule of thumb (all expected counts 5 or more) is met.

A 2 × 2 table: [[10, 20], [20, 10]]. Every expected count is 30 × 30 ÷ 60 = 15, so χ² = 4 × 5² ÷ 15 = 6.666667, df 1, p = 0.009823. With Yates’ correction: 4 × 4.5² ÷ 15 = 5.4, p = 0.020137. Fisher’s exact two-sided p = 0.019383, phi = (10 × 10 − 20 × 20) ÷ √(30⁴) = −0.3333.

Goodness of fit: is a die fair? 60 rolls gave 8, 12, 9, 11, 6, 14. Expected 10 each, so χ² = (4 + 4 + 1 + 1 + 16 + 16) ÷ 10 = 4.2, df 5, p = 0.5210: no evidence the die is unfair (which isn’t proof that it is fair).

What the result does and doesn’t tell you

  • Significant means “unlikely to be chance alone”, if the test’s assumptions hold. It doesn’t say how strong the link is. Use Cramér’s V and the residuals for that.
  • Not significant is not proof of no link. With small samples a real link can easily be missed.
  • It says nothing about cause. Shift and drink being linked doesn’t mean the shift makes people choose a drink.
  • The p-value is not the chance that the rows and columns are unrelated.

Assumptions and the rule of thumb

  • Counts, not percentages or averages. Each cell must be the number of people or things, and each one counts in exactly one cell.
  • Independent observations: no one appears twice. For the same people measured twice (before and after), use McNemar’s test instead.
  • Big enough expected counts. A common rule of thumb: every expected count at least 5 for a 2 × 2 table; for bigger tables, no more than 20% below 5 and none below 1. If that fails, use Fisher’s exact test for 2 × 2, or merge small rows or columns.

Critical chi-square values

dfα = 0.10α = 0.05α = 0.01
12.7063.8416.635
24.6055.9919.210
36.2517.81511.345
47.7799.48813.277
59.23611.07015.086
610.64512.59216.812
813.36215.50720.090
1015.98718.30723.209
1522.30724.99630.578
2028.41231.41037.566
3040.25643.77350.892

p-values come from the chi-square distribution through the regularised incomplete gamma function, and Fisher’s test from the exact hypergeometric probabilities. All were checked against SciPy 1.18.1: for [[10, 20], [20, 10]], χ² = 6.6667, p = 0.009823; Fisher p = 0.019383.

Common questions

How do I do a chi-square test of independence?

Put your counts in a table with one row per group and one column per answer. Add up each row, each column and the grand total. For every cell, the expected count is its row total × its column total ÷ the grand total. Work out (observed − expected)² ÷ expected for every cell and add them all up to get χ². The degrees of freedom are (rows − 1) × (columns − 1). The p-value is the chance of a χ² this big or bigger with those degrees of freedom. For Morning 20, 30, 10 and Evening 30, 15, 15: χ² = 8, df = 2, p = 0.0183.

What does the p-value mean in a chi-square test?

It is the chance of seeing differences between your counts and the expected counts at least this big if the rows and columns were really unrelated (or, for goodness of fit, if the expected pattern were really true). A p-value below your α (often 0.05) is called statistically significant. It is not the chance that there is no link, and it says nothing about how strong the link is: look at Cramér’s V for that.

When should I use Fisher’s exact test instead?

For a 2 × 2 table with small counts. A common rule of thumb says the chi-square p-value can be unreliable when any expected count is below 5 (or, for bigger tables, more than 20% are below 5 or any is below 1). Fisher’s exact test works out the p-value exactly, so it is safe for any sample size.

Should I use Yates’ continuity correction?

It is an old fix for 2 × 2 tables that makes the chi-square test more cautious. Many statisticians now think it is too cautious; Fisher’s exact test is the better choice when counts are small, and the plain test is fine when they aren’t. Some courses and software (R’s chisq.test, SciPy) use it by default for 2 × 2 tables, so match whatever your course or journal expects.

What is the difference between a test of independence and goodness of fit?

A test of independence uses a table with two variables (for example shift and drink) and asks whether they are linked. Goodness of fit uses one variable and asks whether its counts match a pattern you set in advance, such as a fair die (all equal) or Mendel’s 9:3:3:1 ratio.

What is a good Cramér’s V?

Cramér’s V runs from 0 (no link) to 1 (perfect link). For a table with 2 rows or 2 columns, Cohen’s rough guide is 0.1 small, 0.3 medium and 0.5 large. For bigger tables the cut-offs are lower: divide each by √(smaller of rows and columns − 1).

Related calculators

T-test calculatorWelch, Student’s pooled, paired and one-sample t-tests from raw data or mean, SD and n: t, df, p-value, critical t, confidence interval, Cohen’s d and Hedges’ g, with a plain-English verdict.Probability calculatorTwo events (and, or, not, neither), repeated tries, Bayes’ theorem, odds, dice, coins and cards, with exact fractions and the working.Binomial distribution calculatorP(X = k), at most, at least, fewer and more than k successes in n trials, mean and SD, a bar chart, ranges, the inverse, normal and Poisson approximations and a full table, up to 10,000 trials.Sample size calculatorHow many people to survey for your confidence level and margin of error, the margin for a sample you have, means, response rates, design effect and A/B test sample sizes with power.

Made by Zulu Calculator, part of AlphaZulu LLC. Formulas are shown in full and rule figures are checked against official sources; see how we build calculators.

Embed this calculator on your site

Free to use on your website or blog. Paste this code where you want the calculator to appear. Please keep the credit link.

Chi-square test calculator by Zulu Calculator ↗