Skip to main content
ponderloop

Chi-Square Calculator

A 3 × 3 table of 130 counts gives χ² = 9.81271 with 4 degrees of freedom and a p-value of 0.04370. That is at or below the usual significance level α = 0.05, so you reject the null hypothesis that the two variables are independent; at α = 0.01 the same table would fail to reject it. Cramér’s V, the size of the association, is 0.194. The calculator runs Pearson’s chi-square test of independence on a table of observed counts (2 × 2 up to 5 × 5), the goodness-of-fit test on a list of counts, and turns any chi-square statistic and degrees of freedom into a p-value and critical value. It shows the expected counts and the (O − E)² ÷ E table behind the statistic, warns when an expected count is below 5, and leaves Yates’s continuity correction for 2 × 2 tables off unless you tick it.

Updated Runs in your browser: nothing you enter is uploadedHow this tool works

Which test?

Type observed counts (whole numbers, not percentages) for two categorical variables: one row per category of the first, one column per category of the second.

Observed counts

RowColumn 1Column 2Column 3
Row 1
Row 2
Row 3

Test of independence, 3 × 3 table, χ² = 9.81271 with 4 degrees of freedom

P-value 0.04370

p = 0.04370 is at or below α = 0.05, so reject the null hypothesis that the row and column variables are independent. The sample shows evidence of an association; it does not say what causes it or how strong it is.

Chi-square statistic (χ²)
9.81271
Degrees of freedom
4
P-value
0.04370
Critical value at α = 0.05
9.488
Decision
Reject the null hypothesis
Total count (N)
130
Cramér’s V
0.194
Smallest expected count
10.77

The working

Observed counts with row and column totals
ObservedColumn 1Column 2Column 3Total
Row 112181040
Row 22215946
Row 38201644
Total425335130
Expected counts E = row total × column total ÷ N
ExpectedColumn 1Column 2Column 3
Row 112.9216.3110.77
Row 214.8618.7512.38
Row 314.2217.9411.85
(O − E)² ÷ E for each cell
ContributionColumn 1Column 2Column 3
Row 10.06590.17560.0549
Row 23.42880.75140.925
Row 32.71750.23691.4565
χ² (sum)9.81271
  1. Row totals 40, 46, 44; column totals 42, 53, 35; grand total N = 130.
  2. Expected count of each cell = row total × column total ÷ N (second table).
  3. Each cell contributes (O − E)² ÷ E (third table); they add up to χ² = 9.81271.
  4. Degrees of freedom = (rows − 1) × (columns − 1) = (3 − 1) × (3 − 1) = 4.
  5. P-value = P(χ² ≥ 9.81271) with 4 degrees of freedom = 0.04370. Only the right tail counts, because a large statistic is what contradicts independence.
  6. Critical value at α = 0.05 with 4 degrees of freedom is 9.488: the statistic reaches or exceeds it, so reject the null hypothesis.
  7. Cramér’s V = √(χ² ÷ (N × (min(rows, columns) − 1))) = √(9.81271 ÷ (130 × 2)) = 0.194.

Chi-square critical values by degrees of freedom

Upper-tail critical values of the chi-square distribution for 1 to 30 degrees of freedom at α = 0.1, 0.05, 0.01, computed by inverting the distribution; reject the null hypothesis when the statistic is at least the value shown.
Degrees of freedomα = 0.1α = 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
712.01714.06718.475
813.36215.50720.090
914.68416.91921.666
1015.98718.30723.209
1117.27519.67524.725
1218.54921.02626.217
1319.81222.36227.688
1421.06423.68529.141
1522.30724.99630.578
1623.54226.29632.000
1724.76927.58733.409
1825.98928.86934.805
1927.20430.14436.191
2028.41231.41037.566
2129.61532.67138.932
2230.81333.92440.289
2332.00735.17241.638
2433.19636.41542.980
2534.38237.65244.314
2635.56338.88545.642
2736.74140.11346.963
2837.91641.33748.278
2939.08742.55749.588
3040.25643.77350.892

Degrees of freedom and critical values by table size

A table with r rows and c columns has (r − 1)(c − 1) degrees of freedom; the critical values are the ones the calculator reports for that many degrees of freedom.
Table size (rows × columns)Degrees of freedomCritical value at α = 0.05Critical value at α = 0.01
2 × 213.8416.635
2 × 325.9919.210
2 × 437.81511.345
2 × 549.48813.277
3 × 349.48813.277
3 × 4612.59216.812
3 × 5815.50720.090
4 × 4916.91921.666
4 × 51221.02626.217
5 × 51626.29632.000

Cramér’s V: rough size labels by table shape

Cohen’s benchmarks for the effect size w (0.1 small, 0.3 medium, 0.5 large) converted to Cramér’s V as w ÷ √(smaller of rows and columns − 1). Treat them as a starting point, not a verdict.
Smaller of rows and columnsSmallMediumLarge
20.100.300.50
30.070.210.35
40.060.170.29
50.050.150.25

Eight worked examples

Each row is the calculator’s own answer for the data in the row at α = 0.05; in a data cell, / separates the rows of a table.
TestDataχ²dfp-valueDecisionWhat it shows
Independence, 3 × 312 18 10 / 22 15 9 / 8 20 169.8127140.04370Reject the null hypothesisThe calculator’s own example: significant at 5%, not at 1%
Independence, 2 × 320 15 25 / 30 35 159.8437520.007285Reject the null hypothesisA stronger association: significant at both levels
Independence, 2 × 235 15 / 25 254.1666710.04123Reject the null hypothesisNo continuity correction (the default)
Independence, 2 × 2 with Yates35 15 / 25 253.37510.06619Fail to reject the null hypothesisThe same table with the correction: the decision changes
Independence, 2 × 23 1 / 1 3210.1573Fail to reject the null hypothesisEvery expected count is 2: the warning appears
Goodness of fit, equal5 8 9 8 10 2013.450.01991Reject the null hypothesisSixty die rolls against a fair die (10 expected per face)
Goodness of fit, 9 : 3 : 3 : 1315 101 108 320.47002430.9254Fail to reject the null hypothesisA classic textbook pea data set against a 9 : 3 : 3 : 1 ratio
P-value from a statisticχ² = 3.84, df = 13.8410.05004Fail to reject the null hypothesisThe familiar 5% cut-off for one degree of freedom

Expected counts of the 3 × 3 example

Expected count = row total × column total ÷ 130, for the table in the first worked example; the smallest is 10.77.
RowColumn 1Column 2Column 3Row total
Row 112.9216.3110.7740
Row 214.8618.7512.3846
Row 314.2217.9411.8544

How to run a chi-square test with this calculator

  1. Choose the test. Pick “Test of independence” to ask whether two categorical variables are related (counts in a table), “Goodness of fit” to compare one list of counts with an expected distribution, or “P-value from a statistic” if you already have χ² and its degrees of freedom.
  2. Enter the counts. Type observed counts, never percentages, into the grid (the example is a 3 × 3 table of 130). Use Add and Remove to make the grid 2 × 2 up to 5 × 5, or to set the number of categories for a goodness-of-fit test, and either expect equal counts or type the expected proportions.
  3. Set the significance level. Type α before looking at the result (0.05 in the example). The calculator reports the p-value, the critical value for that α and the decision.
  4. Check the expected counts and the working. Read the expected-counts table and the (O − E)² ÷ E contributions: the largest contribution shows which cell drives the result. If any expected count is below 5 a warning appears, because the chi-square approximation is then unreliable. In the example the smallest expected count is 10.77.
  5. State the conclusion carefully. If p ≤ α, reject the null hypothesis; otherwise fail to reject it. Here p = 0.04370, so at α = 0.05 you reject independence, and at α = 0.01 you fail to reject it. Add Cramér’s V (0.194) to say how strong the association is, since a p-value alone does not.

Frequently asked questions

How do I calculate a chi-square test of independence?
Add up each row and column to get the totals and the grand total N, then work out the expected count of every cell as row total × column total ÷ N. Each cell contributes (O − E)² ÷ E, where O is the observed count, and the contributions add up to the statistic. In the example (N = 130) they add up to χ² = 9.81271. The p-value is the chance, if the variables were independent, of a statistic at least that large from a chi-square distribution with (rows − 1)(columns − 1) = 4 degrees of freedom: 0.04370 here. The working below the result shows every step.
How many degrees of freedom does a chi-square test have?
For a test of independence it is (rows − 1) × (columns − 1): 4 for the 3 × 3 example, and 1 for any 2 × 2 table. For a goodness-of-fit test it is the number of categories minus 1, minus one more for every parameter you estimated from the data. For the six-sided die example that is 6 − 1 = 5. The table of table sizes on this page lists the degrees of freedom and critical values from 2 × 2 up to 5 × 5.
How do I get a p-value from a chi-square statistic?
Use “P-value from a statistic”: type χ² and the degrees of freedom. The p-value is the area to the right of the statistic under the chi-square curve. A statistic of 3.84 with 1 degree of freedom has p = 0.05004 and 11.07 with 5 degrees of freedom has p = 0.05001, which is why 3.84 and 11.07 are the familiar 5% cut-offs. Only the right tail is used, because a larger statistic always means a worse fit with the null hypothesis.
What is the chi-square critical value at 0.05?
It depends on the degrees of freedom: 3.841 with 1, 5.991 with 2, 9.488 with 4 and 43.773 with 30. If your statistic is at least the critical value, the p-value is at most 0.05 and you reject the null hypothesis. The critical-value table on this page covers 1 to 30 degrees of freedom at α = 0.1, 0.05, 0.01; the calculator computes any α and degrees of freedom up to 10,000.
What is the difference between the test of independence and goodness of fit?
A goodness-of-fit test compares one categorical variable with a distribution you specify in advance, such as 60 die rolls against a fair die (χ² = 13.4, p = 0.01991), or pea counts against a 9 : 3 : 3 : 1 ratio (χ² = 0.470024, p = 0.9254). A test of independence has two categorical variables measured on the same subjects and asks whether the distribution of one depends on the other; the expected counts come from the table’s own totals, so you specify nothing in advance.
What does it mean if an expected count is below 5?
The p-value comes from the chi-square distribution, which only approximates the real distribution of the statistic, and the approximation gets poor when expected counts are small. The common rule of thumb is that every expected count should be at least 5; some textbooks allow up to 20% of cells below 5 as long as none is below 1. The 2 × 2 table 3 1 / 1 3 has an expected count of 2 in every cell, and the calculator warns: its p-value (0.1573) should not be trusted. Combine categories, collect more data or, for a 2 × 2 table, use an exact test such as Fisher’s.
What is Yates’s correction and is it applied?
Yates’s continuity correction reduces each |O − E| by 0.5 in a 2 × 2 table before squaring, because the chi-square curve is continuous but counts are not. It is off by default here, which matches SciPy’s correction=False and the uncorrected formula taught first; tick the box to apply it (SciPy’s chi2_contingency and R’s chisq.test apply it to 2 × 2 tables unless told not to, so a package may report a different p-value). It lowers the statistic: the table 35 15 / 25 25 gives χ² = 4.16667 and p = 0.04123 without it, and χ² = 3.375 and p = 0.06619 with it, which flips the decision at α = 0.05. Many statisticians consider it too conservative; whichever you use, decide before you see the data and say which one you used.
What is Cramér’s V?
Cramér’s V rescales the statistic to a 0 to 1 measure of association: V = √(χ² ÷ (N × (min(rows, columns) − 1))). It is 0 when the rows and columns are unrelated and 1 when one variable determines the other. The example has V = 0.194, between the small and medium sizes in the Cramér’s V table for a 3 × 3 table, even though the p-value is below 0.05. It matters because the p-value grows more significant with sample size while V does not: the 2 × 2 table 35 15 / 25 25 and the same proportions with ten times the counts (350 150 / 250 250) both have V = 0.204, but p = 0.04123 against 1.082e-10.
Can I enter percentages or proportions instead of counts?
Not for the observed values. The statistic depends on how many observations there are, so typing percentages is the same as claiming exactly 100 observations. The same 35%, 15%, 25%, 25% pattern gives χ² = 4.16667 from 100 observations but χ² = 41.6667 from 1000. Convert percentages back to counts first. Expected proportions in a goodness-of-fit test are different: type them as proportions (0.25, 0.25, 0.5), percentages (with or without the % sign) or ratios such as 9, 3, 3, 1; they are scaled to add up to 1.
How do I word the conclusion: reject or accept?
Say reject or fail to reject the null hypothesis, never accept it. A non-significant result means the sample did not give enough evidence against independence (or against the expected distribution); it does not show they hold, especially with small counts. With the example, p = 0.04370 at α = 0.05 gives “reject the null hypothesis of independence”, and at α = 0.01 the same data give “fail to reject”. Rejection also says nothing about cause: it only says the counts are unlikely if the variables were unrelated.
Why does the goodness-of-fit test have an option for parameters estimated from the data?
If you estimated parameters of the expected distribution from the same data (for example the mean of a Poisson distribution you then fit), each estimate removes one degree of freedom. The same counts 18, 22, 30 against proportions 2 : 3 : 5 give χ² = 1.90476 either way, but p = 0.3858 with 2 degrees of freedom and p = 0.1675 with 1 when one parameter was estimated. Leave it at 0 when the expected proportions were fixed in advance, as for a fair die.
Is a chi-square test one-tailed or two-tailed?
The p-value uses only the right tail of the chi-square distribution, since the statistic is a sum of squares and only large values contradict the null hypothesis. That does not make it a directional test: for a 2 × 2 table it tests “different” in either direction, because the statistic is large whichever way the proportions differ. A statistic of 0 means the observed counts match the expected ones exactly (p = 1).
What assumptions does a chi-square test make?
The observations are independent (each subject or event counted once, no repeated measures on the same subjects), every observation falls in exactly one category, the data are counts rather than percentages or measurements, and the expected counts are large enough. A paired design such as before-and-after on the same people needs a different test (McNemar’s). A very large sample can make a trivial association significant, so read Cramér’s V alongside the p-value.

How it works

Test of independence: for an r × c table of observed counts O with row totals R, column totals C and grand total N, the expected count of a cell is E = R × C ÷ N, the statistic is χ² = Σ (O − E)² ÷ E over all r × c cells, and under independence it approximately follows a chi-square distribution with (r − 1)(c − 1) degrees of freedom (Pearson, 1900). Goodness of fit: the same sum over k categories with E = N × the expected proportion (the typed proportions are divided by their sum), with k − 1 − m degrees of freedom when m parameters were estimated from the data. The p-value is the right-tail area P(χ² ≥ statistic), computed from the regularized upper incomplete gamma function Q(df ÷ 2, statistic ÷ 2) by its series and continued fraction (Numerical Recipes, 6.2) in double precision; critical values invert it by bisection. These agree with SciPy’s chi2.sf and chi2.isf to about 12 significant digits, and the statistic and p-value of the tests agree with scipy.stats.chi2_contingency (correction=False) and scipy.stats.chisquare. Yates’s continuity correction, applied only to 2 × 2 tables when you tick the box, moves each observed count towards its expected count by min(0.5, |O − E|) before squaring, exactly as scipy.stats.chi2_contingency(correction=True). It is off by default. Cramér’s V = √(χ² ÷ (N × (min(r, c) − 1))) uses the statistic shown, so it is also corrected when the correction is on (as in scipy.stats.contingency.association). The warning appears when any expected count is below 5, the usual rule of thumb for the approximation. Counts must be whole numbers; a table with an empty row or column cannot be tested because its expected counts are 0. Everything is computed in double-precision arithmetic in your browser. The page is a calculating aid: whether the test fits your design, and how to interpret a p-value, remain with the person using it.

Sources

Guides

More: Statistics, probability and gradesAll math & numbersAll toolsHome & DIY calculators