Chi-square test of independence

Enter counts, not percentages. The example is an A/B test: row 1 is the control, row 2 the variant; column 1 counts visitors who converted, column 2 those who did not. Free, no sign-up, and nothing you type leaves your browser.

Observed counts, one per cell
Col 1Col 2
Row 1
Row 2

See when to use Yates's correction.

Chi-square test of independence

χ² = 4.8383, p = 0.0278

p = 0.0278 is below 0.05: reject the null hypothesis at the 0.05 level. The rows and the columns are related: the share in each column differs between rows by more than chance would explain.

Degrees of freedom: (2 - 1) × (2 - 1) = 1. Critical value at 0.05: 3.8415, and 4.8383 is above it.

Expected counts (row total × column total ÷ 20,000): row 1: 535, 9,465; row 2: 535, 9,465.

If the rows are two groups and the first column counts conversions, this is the two-proportion z-test: z = 2.1996, z² = 4.8383, the same as chi-square, with the same two-sided p-value.

Cramér's V (effect size, 0 to 1): 0.0156.

Every expected count meets Cochran's rule (none below 1, no more than 20% below 5; the smallest is 535), so the chi-square approximation can be trusted.

Formula

expected = row total * column total / grand total
chi2     = sum of (observed - expected)^2 / expected
df       = (rows - 1) * (columns - 1)
p-value  = P(chi-square with df > chi2)

Short answer

A chi-square calculator tests whether counts in a table differ from what chance would produce. For each cell it squares the gap between observed and expected count, divides by the expected count and adds the results. Compare that statistic with the chi-square distribution for your degrees of freedom to get the p-value. A p-value below 0.05 is significant at the 5% level.

  • Chi-square = the sum of (observed - expected)² ÷ expected over every cell.
  • In a test of independence, expected count = row total × column total ÷ grand total, and degrees of freedom = (rows - 1) × (columns - 1).
  • In a goodness of fit test, expected count = total × the expected share, and degrees of freedom = categories - 1.
  • Check expected counts, not observed ones: by Cochran's rule none should be below 1 and no more than 20% below 5.
  • On a 2 by 2 table of conversions, chi-square without Yates's correction equals z² from the two-proportion z-test, with the same p-value.

Chi-square goodness of fit test

Do counts in one variable match the shares you expected? Leave the expected shares empty for equal shares, or type them as counts, percentages or a ratio such as 1, 2, 1: they are scaled to your total. The example is visitors in a three-way split test.

Observed count and expected share for each category
CategoryObservedExpected share (optional)
1
2
3

Chi-square goodness of fit

χ² = 7.6317, p = 0.0220

p = 0.0220 is below 0.05: reject the null hypothesis at the 0.05 level. The counts do not fit the expected shares.

Degrees of freedom: 3 - 1 = 2. Critical value at 0.05: 5.9915.

Expected counts (19,700 × each expected share, equal shares): 6,566.67, 6,566.67, 6,566.67.

Contributions, (observed - expected)² ÷ expected: 3.2165 + 0.0829 + 4.3323 = 7.6317.

Every expected count meets Cochran's rule (none below 1, no more than 20% below 5; the smallest is 6,566.67), so the chi-square approximation can be trusted.

Formula

expected = total * expected share
chi2     = sum of (observed - expected)^2 / expected
df       = categories - 1

How do you calculate chi-square?

To calculate chi-square, work out the count you would expect in each cell if the null hypothesis were true, subtract it from the count you observed, square the gap, divide by the expected count, and add up the results over every cell. The bigger the total, the further your data sit from what the null hypothesis predicts.

chi2 = sum of (O - E)^2 / E

O = observed count in a cell
E = expected count in that cell if the null hypothesis is true

How to run a chi-square test, step by step

  1. State the null hypothesis. For independence: the two variables are not related. For goodness of fit: the counts follow the expected shares.
  2. Lay out the observed counts in a table, one count per cell. Each person or item must be counted once.
  3. Work out the expected counts. Row total × column total ÷ grand total for independence; total × expected share for goodness of fit.
  4. Check the expected counts are large enough (see small expected counts).
  5. Add up (O - E)² ÷ E over every cell to get the statistic.
  6. Find the degrees of freedom and the p-value. The p-value is the area to the right of the statistic in the chi-square distribution. The p-value calculator does this step on its own if you already have a statistic.
  7. Compare the p-value with your significance level and report the result.

Chi-square test of independence or goodness of fit?

Use the chi-square test of independence when you have two categorical variables, such as page version and whether a visitor converted, and want to know whether they are related. Use the goodness of fit test when you have one variable and a set of shares you expected, such as an even traffic split, and want to know whether the counts match.

The two chi-square tests this calculator runs
Test of independenceGoodness of fit
QuestionAre two variables related?Do counts match the shares you expected?
DataA table of counts, rows by columnsOne count per category, plus expected shares
Expected countRow total × column total ÷ grand totalTotal × expected share
Degrees of freedom(rows - 1) × (columns - 1)Categories - 1
CRO exampleDid the variant convert at a different rate from the control?Did each variant get the share of traffic it was set to get?

The test of homogeneity, which asks whether several groups share the same distribution, uses the same arithmetic as the test of independence, so the first calculator covers it too.

Chi-square calculator example: an A/B test, worked by hand

An A/B test sends 10,000 visitors to the control and 10,000 to the variant. The control converts 500 (5.0%) and the variant 570 (5.7%). The counts are made up to show the arithmetic, and they are the calculator's default values.

  1. Totals: 20,000 visitors, 1,070 conversions and 18,930 visitors who did not convert.
  2. Expected conversions in each group: 10,000 × 1,070 ÷ 20,000 = 535. The table shows every cell.
  3. Add up the four contributions: chi-square = 4.8383.
  4. Degrees of freedom: (2 - 1) × (2 - 1) = 1. The critical value at 0.05 is 3.8415.
  5. p = 0.0278. That is below 0.05, so conversion and page version are related: the variant's rate differs from the control's by more than chance would usually produce.
Observed and expected counts, 20,000 visitors (illustrative numbers)
GroupOutcomeObserved (O)Expected (E)O - E(O - E)² ÷ E
ControlConverted500535-352.2897
ControlDid not convert9,5009,465350.1294
VariantConverted570535352.2897
VariantDid not convert9,4309,465-350.1294

Is a chi-square test the same as a z-test?

On a 2 by 2 table of conversions, the chi-square test without Yates's correction is the same test as the pooled two-proportion z-test that the statistical significance calculator runs. Chi-square equals z squared, and the two-sided p-values match exactly.

  • Two-proportion z-test on the same data: pooled rate 5.35%, z = 2.1996, two-sided p = 0.0278.
  • z² = 2.1996² = 4.8383, the chi-square statistic above, with p = 0.0278.

So for a simple A/B test, use whichever tool you prefer: the answer is the same. The z-test can also run one-sided and gives a confidence interval for the lift; chi-square extends to three or more variants, or more than two outcomes, in a single test. Before you run either, the A/B test sample size calculator tells you how many visitors each version needs, and the confidence interval calculator puts a range on each rate.

Cramér's V for this table is 0.0156, which shows that a statistically significant result can still be a small difference. Whether a lift is worth having is a business question, not a statistical one.

Example: a chi-square test on a 2 by 3 table

A software company wants to know whether new and returning customers choose plans differently. It counts 400 purchases across three plans. The numbers are made up to show the method.

Observed counts, with expected counts in brackets (illustrative numbers)
CustomerBasicProTeamTotal
New customers120 (100)60 (65)20 (35)200
Returning customers80 (100)70 (65)50 (35)200
Total20013070400
  1. Expected count for new customers on Basic: 200 × 200 ÷ 400 = 100. The others follow the same rule.
  2. Chi-square over the six cells = 21.6264, with (2 - 1) × (3 - 1) = 2 degrees of freedom.
  3. p = 2.01e-5, far below 0.05 and above the critical value of 5.9915: plan choice and customer type are related. Cramér's V is 0.2325.

The test says the two groups differ, not where. Compare each cell's observed and expected counts: here new customers chose Basic more often than expected and Team less often.

Goodness of fit example: is your traffic split even?

A goodness of fit test checks whether the counts in one variable match the shares you expected. In conversion testing it catches a sample ratio mismatch: a split test set to send a third of visitors to each version, which recorded 6,712, 6,590, 6,398 visitors, should have about 6,566.67 in each.

  1. Expected count per version: 19,700 ÷ 3 = 6,566.67.
  2. Contributions: 3.2165 + 0.0829 + 4.3323 = chi-square of 7.6317.
  3. Degrees of freedom: 3 - 1 = 2. p = 0.0220.

At the usual 0.05 level that split looks uneven. Because a split check is run on every test, many teams use a stricter threshold such as 0.001 to avoid false alarms; at that level this split passes. The sample ratio mismatch check in the statistical significance calculator runs this test on two groups for you. If a split fails, fix the assignment or the tracking before you trust any result from the test.

Get your free CRO audit

Enter your website and the audit starts right away. Watch it check your page live: eight checks, each scored out of 100, and three fixes you can make now.

What if the expected counts are too small?

The chi-square p-value is an approximation that works when expected counts are large enough. This calculator applies Cochran's rule: no expected count below 1, and no more than 20% of them below 5. On a 2 by 2 table that means every expected count must be at least 5. When the rule fails, the calculator still shows the result, with a warning.

The rule comes from W. G. Cochran, "Some methods for strengthening the common χ² tests", Biometrics 10(4), 1954, and is widely repeated in statistics textbooks. Note that it is about expected counts, not observed ones: an observed 0 is fine if its expected count is large.

  • Collect more data if you can. Expected counts grow with the sample.
  • Combine categories that belong together, so each cell holds more.
  • On a 2 by 2 table, use Fisher's exact test, which computes the p-value exactly instead of approximating it. This calculator does not run it.

Should you use Yates's continuity correction?

Yates's continuity correction subtracts 0.5 from each gap between observed and expected counts before squaring, on a 2 by 2 table only. It makes the test more conservative: the statistic falls and the p-value rises. Frank Yates proposed it in 1934 because counts are whole numbers while the chi-square distribution is smooth.

The trade-off: the correction protects against calling a result significant too easily on small samples, but it often overcorrects: the real rate of false positives ends up below the significance level you chose, and the test loses power to find real differences. With large counts it changes almost nothing; on the A/B example above it moves chi-square from 4.8383 to 4.701 and p from 0.0278 to 0.0301. On a small table it can change the decision:

  • A table of 3 and 9 in row 1 and 8 and 4 in row 2 has expected counts of 5.5 and 6.5 in each row.
  • Without the correction: chi-square = 4.1958, p = 0.0405, significant at 0.05.
  • With Yates's correction: chi-square = 2.6853, p = 0.1013, not significant at 0.05.

Many statisticians now prefer the uncorrected test for 2 by 2 tables, with Fisher's exact test when expected counts are small. If you report a corrected result, say so. The calculator applies the correction the way R's chisq.test and SciPy do: a gap smaller than 0.5 is reduced to 0, never past it.

Chi-square critical values table

A chi-square critical value is the statistic that leaves exactly your significance level in the right tail of the distribution. If your statistic is larger than the critical value for your degrees of freedom, the p-value is below the significance level and you reject the null hypothesis. The calculator shows the critical value for your test; the table lists the common ones.

Right-tail chi-square critical values, computed with the calculator's own quantile function
Degrees of freedom0.100.050.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

How to do a chi-square test in Excel or Google Sheets

To do a chi-square test in Excel or Google Sheets, put the observed counts in one range and the expected counts in a range of the same shape, then use =CHISQ.TEST(observed, expected). It returns the p-value, not the statistic. Excel and Google Sheets have the same three functions.

Spreadsheet functions, with the A/B example's observed counts in B2:C3 and expected counts in E2:F3
To getFormulaResult
Expected count, first cell=SUM($B2:$C2)*SUM(B$2:B$3)/SUM($B$2:$C$3)535
p-value from the counts=CHISQ.TEST(B2:C3,E2:F3)0.0278
Chi-square statistic=SUMPRODUCT((B2:C3-E2:F3)^2/E2:F3)4.8383
p-value from a statistic=CHISQ.DIST.RT(4.8383,1)0.0278
Critical value at 0.05=CHISQ.INV.RT(0.05,1)3.8415

Fill the expected-count formula across E2:F3. CHISQ.TEST works out the degrees of freedom from the shape of the range: (rows - 1) × (columns - 1) for a table, or the number of cells - 1 for a single row or column, which makes it a goodness of fit test. It never applies Yates's correction. The older CHITEST, CHIDIST and CHIINV functions give the same results.

How do you report a chi-square result?

Report a chi-square result with the statistic, its degrees of freedom, the sample size and the p-value, in the form χ²(df, N = n) = statistic, p = value. The A/B example is χ²(1, N = 20,000) = 4.8383, p = 0.0278. Add the rates or the expected counts so a reader can see the direction of the difference.

  • Say which test you ran: independence or goodness of fit, and whether Yates's correction was used.
  • Give an effect size, such as Cramér's V or the difference in rates, not only the p-value.
  • Write "fail to reject the null hypothesis" when p is above the significance level, never "the groups are the same".

Chi-square is one of several ways to read a test. These tools cover the steps around it.

See all free tools and how they fit together. When a test result tells you a page is underperforming, Convertica's free CRO audit checks that page and gives you three fixes to test next.

Chi-square calculator FAQ

How does a chi-square calculator work?

A chi-square calculator works out the count each cell would have if the null hypothesis were true, then adds up (observed - expected)² ÷ expected over every cell. That sum is the chi-square statistic. The calculator then finds the area to its right in the chi-square distribution with your degrees of freedom: that area is the p-value.

How do you calculate expected counts for a chi-square test?

In a test of independence, multiply the row total by the column total and divide by the grand total. In a table of 20,000 visitors with 10,000 in the control and 1,070 conversions overall, the control's expected conversions are 10,000 × 1,070 ÷ 20,000 = 535. In a goodness of fit test, multiply the total by each category's expected share.

How do you find the degrees of freedom for a chi-square test?

For a test of independence, degrees of freedom = (rows - 1) × (columns - 1), so a 2 by 2 table has 1 and a 3 by 4 table has 6. For a goodness of fit test, degrees of freedom = the number of categories - 1. Count rows, columns and categories, never visitors or observations.

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

The p-value is the probability of a chi-square statistic at least as large as yours if the null hypothesis were true: no relationship between rows and columns, or counts that match the expected shares. A p-value below your significance level, often 0.05, means you reject the null hypothesis. It does not tell you how large or important the difference is.

When should you not use a chi-square test?

Do not use it when expected counts are small (by Cochran's rule, any below 1 or more than 20% below 5), when the same person or item is counted in more than one cell, or on percentages or averages instead of counts. For a small 2 by 2 table, use Fisher's exact test instead.

Is a chi-square test the same as a z-test for two proportions?

On a 2 by 2 table, yes. The chi-square statistic without Yates's correction equals the square of the z statistic from a pooled two-proportion z-test, and the two-sided p-values are identical. An A/B test with 500 and 570 conversions from 10,000 visitors each gives z = 2.1996 and chi-square = 4.8383 = 2.1996², both with p = 0.0278.

Should I use Yates's continuity correction?

Usually not. Yates's correction makes a 2 by 2 chi-square test more conservative: the statistic falls and the p-value rises. With large counts it barely matters. With small counts it often overcorrects, so many statisticians prefer the uncorrected test, or Fisher's exact test when expected counts are below 5.

How do I do a chi-square test in Excel?

Put the observed counts in one range and the expected counts in a range of the same shape, then use =CHISQ.TEST(observed, expected) for the p-value. For the statistic, add up (observed - expected)² ÷ expected yourself. =CHISQ.DIST.RT(statistic, df) turns a statistic into a p-value, and =CHISQ.INV.RT(0.05, df) gives the critical value.

Find out what is costing you conversions

Enter your website and the audit starts right away. Watch it check your page live: eight checks, each scored out of 100, and three fixes you can make now.