Chi-Square CalculatorChi-Square Calculator
Contingency tables

Chi-Square Test of Independence Calculator

Enter a contingency table of counts, or paste one from Excel. The test checks whether the row variable and the column variable are related, and shows where any difference sits.

Column 1Column 2Column 3
Row 1
Row 2
Row 3
Paste a table from Excel or a CSV file
Chi-square (χ²)12.9909
Degrees of freedom4
p-value0.0113
Cramér's V0.0880
Critical value at α = 0.059.4877

p is below α = 0.05: evidence of an association between the row and column variables at the 5% level.

Every expected count is at least 5 (smallest 49.24), so the chi-square approximation is fine by the strict textbook rule and by Cochran's rule.

Expected counts, residuals and G-test
Column 1Column 2Column 3
Row 190.57 (observed 111)115.19 (observed 96)49.24 (observed 48)
Row 2103.00 (observed 96)131.00 (observed 133)56.00 (observed 61)
Row 3104.42 (observed 91)132.81 (observed 150)56.77 (observed 53)

Adjusted (standardized) residuals, as R's stdres. Cells beyond ±1.96 are marked: they contribute most to the association.

Column 1Column 2Column 3
Row 13.20−2.89−0.24
Row 2−1.060.290.92
Row 3−2.032.50−0.69

Likelihood-ratio G-test: G = 12.8661, df 4, p = 0.0119. N = 839.

APA style χ²(4, N = 839) = 12.99, p = .011

Reproduce this result in R or Python

R

tab <- matrix(c(111, 96, 48, 96, 133, 61, 91, 150, 53), nrow = 3, byrow = TRUE)
res <- chisq.test(tab, correct = FALSE)   # Pearson, no Yates correction
res                     # X-squared, df, p-value
res$expected            # expected counts
res$stdres              # adjusted residuals
sqrt(res$statistic / sum(tab) / (min(dim(tab)) - 1))   # Cramer's V

Python (SciPy)

import numpy as np
from scipy.stats import chi2_contingency
tab = np.array([[111,96,48],[96,133,61],[91,150,53]])
res = chi2_contingency(tab, correction=False)   # Pearson, no Yates correction
print(res.statistic, res.dof, res.pvalue)
print(res.expected_freq)
n = tab.sum()
print(np.sqrt(res.statistic / n / (min(tab.shape) - 1)))   # Cramer's V

Checked on November 21, 2026. Results computed by our statistics engine, version 1.0.0.

On this page

When to use a test of independence

Use it when you have one sample and you recorded two categorical variables for each member, such as year group and preferred study method, or treatment and outcome. The null hypothesis says the two variables are independent: knowing someone's row tells you nothing about their column. The alternative says they are associated.

If instead you drew separate samples from several groups and recorded one variable, the same arithmetic is called a test of homogeneity, and the null hypothesis says the groups share one distribution. The numbers do not change; only the wording of the conclusion does. The guide to choosing a chi-square test sets the two side by side.

Worked example: volunteer hours

OpenStax's Introductory Statistics uses this table of 839 volunteers, classified by type of volunteer and by the hours they volunteered each week (OpenStax 11.3, Example 11.6). It is pre-filled above.

1 to 3 hours4 to 6 hours7 to 9 hours
Community college students1119648
Four-year college students9613361
Nonstudents9115053

Each expected count is the row total times the column total divided by 839. For community college students volunteering 1 to 3 hours that is 90.57, against 111 observed. Summing (O − E)² / E over the nine cells gives χ² = 12.9909 with (3 − 1)(3 − 1) = 4 degrees of freedom and p = 0.0113. At the 5% level there is evidence that hours volunteered depend on the type of volunteer; the textbook reaches the same conclusion.

The single largest contribution, 4.607, comes from community college students volunteering 1 to 3 hours. Cramér's V is only 0.088, so the association is real but weak.

Residuals: where the difference is

A significant χ² says the table departs from independence somewhere, not where. The adjusted (standardized) residual for a cell is (O − E) divided by its standard error, and behaves roughly like a z-score when there is no association. Cells beyond about ±1.96 are the ones driving the result. They match R's chisq.test(...)$stdres, and the calculator marks them.

In the volunteer table, the adjusted residual for community college students at 1 to 3 hours is 3.20 and for nonstudents at 4 to 6 hours it is 2.50. Treat residuals as a guide to describing the pattern, not as a new set of significance tests: with many cells, a few will exceed ±2 by chance.

The G-test option

The likelihood-ratio G-test, G = 2 Σ O ln(O / E), answers the same question and is the default in some fields. With large expected counts G and χ² are close: for the volunteer table G = 12.8661 (p = 0.0119) against χ² = 12.9909. When they disagree noticeably, expected counts are probably too small for either approximation. SciPy computes G with lambda_="log-likelihood" (SciPy chi2_contingency).

A result that is not significant

A Wisconsin statistics course uses a 3x3 table of 529 observations (Statistics 571 appendix). It gives χ² = 1.8571, df 4, p = 0.7620, the same as the R output printed in the course notes. That is no evidence of an association at the 5% level. It does not prove independence: a larger sample might detect a small association that this one cannot.

Entering your table

  • Type counts into the grid, or open "Paste a table" and paste cells copied from Excel or Google Sheets, one row per line.
  • Rows and columns can each go from 2 to 10. Every row and column needs a total above zero.
  • Use counts only. If you have percentages, convert them back to counts with the group sizes.
  • For a 2x2 table, the result adds the Yates-corrected and N−1 statistics and Fisher's exact test automatically; the 2x2 calculator explains them.

Common questions

What is the difference between independence and homogeneity?

The design. Independence: one sample, two variables. Homogeneity: several samples, one variable. The chi-square value and p-value are identical.

How many degrees of freedom does my table have?

(rows − 1) times (columns − 1). A 3x4 table has 6.

Does the order of rows and columns matter?

No. Swapping rows, columns, or the whole table (a transpose) leaves χ² and p unchanged.

Sources