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.
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 hours | 4 to 6 hours | 7 to 9 hours | |
|---|---|---|---|
| Community college students | 111 | 96 | 48 |
| Four-year college students | 96 | 133 | 61 |
| Nonstudents | 91 | 150 | 53 |
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
- OpenStax, Introductory Statistics 2e, section 11.3: test of independence checked November 21, 2026
- SciPy documentation: scipy.stats.chi2_contingency checked November 21, 2026
- Nordheim, Clayton and Yandell, University of Wisconsin Statistics 571, R appendix 13 (2003) checked November 21, 2026