Bell Statistics

Chi-square test calculator

Paste a table of counts and get the Pearson chi-square statistic, its degrees of freedom, the p-value, every expected count and Cramér's V. It handles both jobs the test does: independence between two categorical variables, and goodness-of-fit of one variable against a set of expected proportions. The sample-size tab sizes the table in advance from Cohen's w.

Allon Korem

Written by Allon Korem

Chief Executive Officer

Last updated

Calculator

0.1 small, 0.3 medium, 0.5 large.

Categories of the first variable.

Categories of the second.

Required total sample size
Observations in totalAcross the whole table, not per cell.964
Degrees of freedom2
Achieved powerAt the whole-number sample above.80.0%
Critical valueThe χ² the test has to clear.5.991
Non-centrality (λ)N·w², what the test actually sees.9.640

Collect 964 observations in total — spread across the whole table, not 964 per row — and the test will detect an association as strong as Cohen's w of 0.100 about 80.0% of the time, on 2 degrees of freedom. A larger table needs more for the same effect, because it gives chance more ways to look uneven. The requirement scales as 1/w², so halving the association you want to catch quadruples the data — and what you get for it is still only the omnibus answer, never which category was responsible.

Sample size in total against statistical powerReaching 5.1% power takes 1 in total and 98.2% takes 1,921; the 80.0% target is met at 964.2004006008001,0001,2001,4001,6001,8000%25%50%75%100%PowerSample size — in total80.0% → 964

Drag the dashed line — or focus it and use the arrow keys — to change the target power and resize the study.

Show these numbers as a table
Power at each sample size in total
PowerSample size
5.1%1
18.9%161
34.2%321
48.7%481
61.4%641
71.8%801
79.9%961
86.0%1,121
90.4%1,281
93.5%1,441
95.7%1,601
97.2%1,761
98.2%1,921
Required observations in total against effect size (cohen's w)Detecting 0.05 takes 3,854 and 0.60 takes 27. At the 0.10 currently entered it is 964 — the requirement falls roughly as the square of the effect.1001,0000.100.200.300.400.500.60Effect size (Cohen's w)Required observations in total (log scale)0.10 → 964

Drag the dashed line — or focus it and use the arrow keys — to change effect size (cohen's w).

Show these numbers as a table
Required observations in total against effect size (cohen's w)
Effect size (Cohen's w)Required observations in total
0.053,854
0.11851
0.16364
0.22201
0.28127
0.3388
0.3964
0.4449
0.5039
0.5631

When to use it

Reach for chi-square when both variables are categorical and you want to know whether they are related at all: channel by plan tier, subject line by opened-or-not, device by drop-off step, region by churn reason. The test compares what you observed against what independence would have produced given the row and column totals, and asks whether the gap is bigger than chance. Goodness-of-fit is the same machinery with one row — traffic across five landing pages against the split you expected.

The result is deliberately blunt. A significant chi-square says "something in this table is not independent"; it does not say which cell, which pair, or in which direction. On a 2×2 table that is unambiguous, and the test is identical to the two-proportion z-test — squaring the z gives the chi-square exactly. Anything larger needs a follow-up, and that is where discipline is required: comparing every pair of rows after an omnibus test is precisely what multiple comparison corrections exist for.

Some tables want a different test. When counts are small — any expected count below about five — the approximation breaks and Fisher's exact test computes the answer instead. When the same subjects appear in both rows and columns, as in a before-and-after survey, the data is paired and McNemar's test is correct; chi-square treats it as independent and understates the evidence. When the outcome is a number rather than a category, one-way ANOVA compares means. And when it is "how long until it happened", the table has discarded the timing and censoring that the log-rank test preserves.

Assumptions

Three of these are ritual and one is real. The expected-count rule gets the textbook attention; independence is what actually invalidates results.

  • Every observation falls in exactly one cell, and observations are independent. Counting sessions when you sampled users puts the same unit in the table several times: the totals look larger, the chi-square inflates roughly in proportion, and the p-value becomes meaningless. There is no diagnostic and no repair — it is a property of collection, much as randomisation is a property of assignment.
  • The cells are counts, not percentages, rates or averages. Feeding conversion rates into a chi-square test produces a number, and the number is nonsense. If you only have percentages, reconstruct the counts from the denominators first.
  • Expected counts are large enough for the approximation. The conventional rule — all expected counts at least 5 — is stricter than the evidence supports; a widely used relaxation allows a fifth of cells below 5 provided none is below 1. This calculator reports every expected count and flags the small ones rather than refusing to compute, because the right response depends on the table: collapse sparse categories, or move to an exact test.
  • The categories were fixed before you saw the data. Merging two rows because they looked similar, or splitting a column where the difference was largest, converts an honest test into a search.

How the calculation works

The statistic is Pearson's: for each cell, the squared gap between observed and expected, scaled by expected, summed across the table. Under independence it follows a chi-square distribution on (r−1)(c−1) degrees of freedom, and the p-value is the upper tail. Because every deviation is squared the test is inherently two-sided — there is no one-tailed chi-square. Sample size runs the same distribution non-centrally: you give an effect size as Cohen's w, and the calculator finds the total N at which the non-central chi-square clears the critical value with your chosen probability. Cramér's V sits next to the p-value on purpose, because on a large table the p-value alone makes a negligible association look like a finding — the failure mode described in [reporting results properly](/post/statistically-speaking-how-to-properly-report-a-b-testing-results).

Expected counts
Eᵢⱼ = (row totalᵢ × column totalⱼ) / N

What the cell would hold on average if the two variables were unrelated and the margins were as observed. For goodness-of-fit it is simply N × pᵢ, with pᵢ the hypothesised proportion.

Pearson chi-square statistic
χ² = Σᵢⱼ (Oᵢⱼ − Eᵢⱼ)² / Eᵢⱼ

Dividing by the expected count is what makes a gap of 30 in a cell expecting 100 count for far less than the same gap in a cell expecting 10.

Degrees of freedom
df = (r − 1)(c − 1) [independence]; df = k − 1 [goodness-of-fit]

Independent of N. Adding observations makes a given χ² more significant; adding categories makes it less, because a bigger table has more ways to look uneven by chance.

Cramér's V
V = √( χ² / (N · min(r − 1, c − 1)) )

The effect size: 0 to 1, and free of sample size. On a 2×2 table it equals the phi coefficient, the correlation between the two binary variables. Interpret it in context, but treat anything under about 0.1 as too weak to build a decision on however small the p-value.

Effect size for planning (Cohen's w)
w = √( Σ (p₁ᵢ − p₀ᵢ)² / p₀ᵢ ) and w = V·√(min(r−1, c−1))

Cohen's benchmarks are 0.1 small, 0.3 medium, 0.5 large — benchmarks, not standards. A w of 0.05 can be commercially enormous on a table of a million sessions.

Sample size
N = λ(df, α, 1−β) / w²

λ is the non-centrality at which a non-central chi-square on df degrees of freedom clears the critical value with the target power. At α = 0.05 and 80% power it is about 7.85 for df = 1, 9.63 for df = 2 and 10.90 for df = 3 — so a 3×2 table needs roughly 964 observations to detect w = 0.1.

Worked example

You tested three subject lines on a newsletter, 2,000 sends each, and want to know whether click-through differs before anyone declares a winner. A got 210 clicks, B got 246 and C got 189 — 10.5%, 12.3% and 9.45% against an overall 10.75%.

Table
3 rows (variants) × 2 columns (clicked / not)
Row A
210 clicked, 1,790 not
Row B
246 clicked, 1,754 not
Row C
189 clicked, 1,811 not
Test
Independence, α = 0.05

χ² = 8.66 on 2 degrees of freedom, p = 0.013. Expected clicks are 215 in every row, so no cell is anywhere near the small-count warning. Cramér's V = 0.038.

The subject lines are not interchangeable — a gap this size across three arms of 2,000 turns up by chance about once in seventy-five. But V = 0.038 says the association is close to nothing: which line someone received explains a negligible share of whether they clicked. Both are true at once, and reporting only the first is how a three-point relative difference becomes a breakthrough in a deck. The test also names no winner: the omnibus p-value covers the whole table, and showing that B genuinely beats C needs a pairwise comparison with the multiplicity accounted for — a comparison a good deal less impressive than 0.013 sounds.

Interpreting the output

Read the effect size and the p-value together, and let the effect size lead. Chi-square is unusually good at producing significance from nothing: the statistic grows linearly with N while the pattern in the table stays put, so any table with a real but trivial association crosses 0.05 once the sample is large enough. Cramér's V is invariant to that. When V is 0.03 and p is 0.001, the honest summary is "a real association, too small to act on".

Then look at the cells. An omnibus p-value says the table is not independent; it does not say where. Standardised residuals — each cell's signed contribution to χ² — show which cells drive the result, and a table where one row supplies nearly all the statistic tells a different story from one where every cell is slightly off. Use them to form the follow-up question, not as p-values in their own right.

Be honest about the direction of inference. Chi-square detects association, and association in observational counts is almost always partly confounded. A table showing that paid-social users churn more is equally compatible with paid social attracting different people; separating the two needs a design built for it, or a randomised comparison sized with the A/B test calculator.

Finally, mind the small-count warning rather than working around it. If several expected counts sit below five the p-value is approximate in an unhelpful direction, and the usual instinct — merging categories until the warning disappears — changes the hypothesis being tested. For a 2×2 table Fisher's exact test removes the problem; for larger sparse tables, collapse on grounds decided in advance, or use a simulated p-value.

Frequently asked questions

Chi-square or Fisher's exact test?
Fisher whenever the counts are small, chi-square when they are not. The practical threshold is the expected counts, not the observed ones: if all of them are comfortably above five, the two tests give nearly identical answers and chi-square is fine and faster. Below that, the chi-square approximation drifts and Fisher's exact test is simply correct, because it enumerates the possible tables instead of approximating them. On a large table there is no contest — chi-square is the only practical option, and the small-count issue is handled by collapsing categories rather than by an exact test.
Should I apply Yates' continuity correction?
Usually not. Yates' correction was designed to make the chi-square approximation on a 2×2 table behave more like Fisher's exact test, and it succeeds — including in being conservative, sometimes markedly so. If your counts are large enough that the correction changes nothing, you do not need it; if they are small enough that it changes the answer, you should be running Fisher's exact test rather than a patched approximation. The correction applies only to 2×2 tables in any case.
The test is significant. Which category is responsible?
The test cannot tell you, by design. Look at the standardised residuals, which give each cell's signed contribution to the statistic: values beyond roughly plus or minus two mark cells much further from expectation than independence would produce. Treat those as the source of a hypothesis, not as a set of results. If you then want to claim a specific pair of categories differs, run that comparison as its own test and correct for the number of comparisons you made.
My p-value is tiny but Cramér's V is 0.03. What does that mean?
That you have a large sample and a negligible association, and both parts are true. The chi-square statistic scales with the number of observations, so with enough data any deviation from perfect independence becomes statistically detectable. Cramér's V does not scale that way, which is why it is the number to report alongside. A V of 0.03 means the variables are barely related; the correct conclusion is that you have precisely measured something too small to matter.
Can I run the test on percentages instead of counts?
No, and this is the most damaging mistake made with this test. The chi-square statistic depends directly on the number of observations behind each cell, which is exactly what a percentage throws away. Entering percentages that happen to sum to 100 tells the test you have 100 observations, and the p-value that comes back describes a study you did not run. Recover the raw counts from the denominators first; if you cannot, you cannot run the test.
How large a sample does a chi-square test need?
It depends on the effect size and the shape of the table. At 5% significance and 80% power, detecting a small association of Cohen's w = 0.1 takes about 785 observations on a 2×2 table, about 964 on a 3×2 and about 1,091 on a 4×2 — bigger tables need more because there are more ways for chance to produce unevenness. Detecting a genuinely small effect of w = 0.05 quadruples all of those. Plan with the sample-size tab and pick w from a pilot, a previous table, or the smallest pattern that would change a decision.

Related calculators

  • One-way ANOVA

    Three or more independent groups on one continuous outcome — size it, then run the F test.

  • McNemar's test

    Paired yes/no data — only the pairs that disagree carry any information, and this sizes on them.

  • Fisher's exact test

    The right test for a 2×2 table of small counts — exact p-values, no normal approximation.

  • Log-rank test

    Compare two survival, retention or churn curves — events needed to plan, chi-square and p-value to analyse.

Terms on this page

  • A/B testing

    A randomised experiment on live traffic — and randomisation is the only part that makes it causal.

  • Randomization

    The one mechanism that makes a comparison causal — and the four ways it silently fails.

  • Sample ratio mismatch

    The split is wrong, so the randomisation is broken — the cheapest and most decisive check you can run.

  • Guardrail metric

    A metric that can veto a launch but never justify one, and why that asymmetry is the whole point.

  • P-value

    How surprising your data would be if there were no effect — and the four things it is constantly mistaken for.

  • Significance level

    The false-positive rate you agree to in advance — a budget, and one most teams overspend.

  • Type I error

    The false positive — and the one whose cost lands months later, on a roadmap built around noise.

  • Multiple comparisons

    Test enough things and something will look significant — the arithmetic, and the four fixes.

  • Confounding variable

    A common cause of both variables — the reason a strong, stable correlation can mean nothing.

  • Selection bias

    When who ends up in the data is not who you meant to study — and more data makes it worse.

  • Propensity score matching

    Pair like with like on the probability of being treated — and hope nothing important went unmeasured.

  • Correlation

    How tightly two variables move together — bounded, unitless, and silent about cause.

Talk to the people who build these for a living

We turn tables of counts into decisions, with the effect size reported next to the p-value rather than instead of it. A/B Testing

References

  • Agresti, A. (2013). Categorical Data Analysis (3rd ed.). Wiley.
  • Cohen, J. (1988). Statistical Power Analysis for the Behavioral Sciences (2nd ed.). Lawrence Erlbaum Associates.
  • Cochran, W. G. (1954). Some methods for strengthening the common chi-square tests. Biometrics, 10(4), 417-451.