Chi-Square Calculator
Run a chi-square test on a table of counts, up to 8 by 8, to see whether two things are associated, with Fisher's exact test, Yates' correction and the G-test beside it, the cells that stand out, and a 2 × 2 table's odds ratio and relative risk. Or test counts against an expected ratio, such as 3:1 or 9:3:3:1, or find the P value and critical value of a χ² you already have.
Calculator
Chi-square test
Are two things related? Counts in a table, one row per group and one column per outcome: the test of independence, or of homogeneity.
Doll and Hill asked 60 women with lung cancer and 60 women in hospital with other diseases whether they smoked: 41 and 28 did. Is smoking associated with lung cancer?
Doll & Hill, Smoking and carcinoma of the lung, BMJ 1950;2:739–748, Table IV. They found χ² = 5.76 with 1 degree of freedom, 0.01 < P < 0.02.
Counts of individuals, each counted once. Type over the names, or paste a table from a spreadsheet into any cell, names and all.
Significant
A significant association
- χ²
- 5.763
- df
- 1
- P
- 0.0164
χ² = 5.763 with 1 degree of freedom is above 3.841, the critical value at 0.05, so P = 0.0164: if the rows and columns were independent, counts this far from the expected would be rare. Smokers: 68.3% of Lung cancer against 46.7% of Controls.
For a report: χ²(1, N = 120) = 5.76, p = .016, φ = .22
Counted and expected
▲ more and ▼ fewer than expected, where the adjusted residual passes ±1.96: the cells that make the difference.
| Smokers | Non-smokers | Total | |
|---|---|---|---|
| Lung cancer | 4134.50, more than expected | 1925.50, fewer than expected | 60 |
| Controls | 2834.50, fewer than expected | 3225.50, more than expected | 60 |
| Total | 69 | 51 | 120 |
How strong
Read with the rows as the groups and Smokers as the outcome: Smokers is 68.3% of Lung cancer and 46.7% of Controls, so its risk is 1.46 times and its odds 2.47 times as high in Lung cancer. A case-control study can give only the odds ratio; relative risk needs groups followed up, as in a cohort or a trial. Swap rows and columns above if your table runs the other way.
- φ (Cramér's V)
- 0.219
- Small, by Cohen's guide
- Odds ratio
- 2.47
- 95% CI 1.17 to 5.19
- Relative risk
- 1.46
- 95% CI 1.06 to 2.02
Working
- 01N = 120; row totals 60, 60; column totals 69, 51
- 02E = row total × column total ÷ N
- 03Lung cancer, Smokers: E = 60 × 69 ÷ 120 = 34.50; (41 − 34.50)² ÷ 34.50 = 1.2246
- 04Lung cancer, Non-smokers: E = 60 × 51 ÷ 120 = 25.50; (19 − 25.50)² ÷ 25.50 = 1.6569
- 05Controls, Smokers: E = 60 × 69 ÷ 120 = 34.50; (28 − 34.50)² ÷ 34.50 = 1.2246
- 06Controls, Non-smokers: E = 60 × 51 ÷ 120 = 25.50; (32 − 25.50)² ÷ 25.50 = 1.6569
- 07χ² = 1.2246 + 1.6569 + 1.2246 + 1.6569 = 5.763
- 08df = (rows − 1) × (columns − 1) = (2 − 1) × (2 − 1) = 1
- 095.763 > 3.841, the critical value for df 1 at 0.05, so P = 0.0164 < 0.05
The chi-square distribution, df 1
Worked example
Smoking and lung cancer: Doll and Hill's women, 1950
- 01Smokers: 41 of 60 women with lung cancer, 28 of 60 controls; N = 120
- 02Expected smokers in each group: 60 × 69 ÷ 120 = 34.5; non-smokers: 60 × 51 ÷ 120 = 25.5
- 03Smokers: (41 − 34.5)² ÷ 34.5 = 1.2246; non-smokers: (19 − 25.5)² ÷ 25.5 = 1.6569; the controls give the same
- 04χ² = 1.2246 + 1.6569 + 1.2246 + 1.6569 = 5.763
- 05df = (2 − 1) × (2 − 1) = 1; critical value at 0.05 = 3.841
χ² = 5.763 is above 3.841, so P = 0.0164: smoking was associated with lung cancer, as Doll and Hill found (χ² = 5.76, 0.01 < P < 0.02). The odds of having smoked were 2.47 times as high in the women with lung cancer (95% CI 1.17 to 5.19).
How it works
How to do a chi-square test
A chi-square test compares the counts you observed with the counts you would expect if nothing were going on: the null hypothesis. In a table, nothing going on means the rows and columns are independent, so each row splits across the columns in the same proportions as the whole sample, and a cell expects its row total times its column total, divided by N. In a goodness-of-fit test, it means the counts follow the ratio you expect, so each category expects its share of N.
For each cell, square the difference between observed and expected and divide by the expected: (O − E)² ÷ E. Add them up for χ². The bigger it is, the further the counts are from what the null hypothesis predicts. P is the chance of a χ² at least this large if the null hypothesis were true, read from the χ² distribution for your degrees of freedom. Below 0.05, or the α you chose, the result is significant: counts this far from the expected would be rare by chance alone.
Degrees of freedom count the cells that could vary once the totals are fixed: (rows − 1) × (columns − 1) for a table and categories − 1 for goodness of fit. A 2 × 2 table has 1, so its critical value at 0.05 is 3.841; a 3 × 3 table has 4, with 9.488. When the expected ratio was worked out from the same counts, as in a Hardy-Weinberg test, take off one more for each value estimated.
Chi-square is an approximation that holds when the expected counts are large enough. With small counts, Fisher's exact test weighs every table with the same row and column totals and adds up the chance of those no likelier than yours. The G-test, the likelihood ratio, is an alternative to Pearson's χ² with the same df, and gives nearly the same answer in a large sample. A significant result says only that an association exists: the adjusted residuals show which cells drive it, and Cramér's V, or a 2 × 2 table's odds ratio and relative risk, how strong it is.
Questions
Frequently asked
When do you use a chi-square test?
When your data are counts in categories: how many people, plants or cells fall in each group. Use the test of independence to ask whether two categorical variables are associated, such as smoking and lung cancer, or treatment and recovery, and the goodness-of-fit test to ask whether counts match an expected ratio, such as Mendel's 3:1. For measurements, such as weight or blood pressure, use a t-test or ANOVA instead.
How do you calculate degrees of freedom for chi-square?
For a contingency table, (rows − 1) × (columns − 1): 1 for a 2 × 2 table, 2 for a 2 × 3 and 4 for a 3 × 3. For a goodness-of-fit test, the number of categories minus 1: 3 for the four classes of a 9:3:3:1 dihybrid cross. Take off one more for each parameter estimated from the same counts, such as the allele frequency in a Hardy-Weinberg test.
What is the critical value of chi-square at 0.05?
3.841 for 1 degree of freedom, 5.991 for 2, 7.815 for 3, 9.488 for 4 and 11.070 for 5. If your χ² is at least the critical value for its df, P is below 0.05 and the result is significant at that level. The full chi-square table, for every df to 30 and by tens to 100, is at the foot of this page.
What is the difference between the chi-square tests of independence, homogeneity and goodness of fit?
Independence and homogeneity are worked out the same way, on a table of counts, and differ in the design. A test of independence takes one sample and classifies each individual two ways, such as hair and eye colour. A test of homogeneity takes separate samples, such as a vaccine and a placebo group, and asks whether they split across the outcomes in the same proportions. Goodness of fit has one row of counts and asks whether it matches a ratio set in advance.
When should you use Fisher's exact test instead of chi-square?
When the expected counts are small: below 5 in any cell of a 2 × 2 table, or below 5 in more than a fifth of a bigger table's cells, or below 1 anywhere. Chi-square's P is an approximation that fails with small counts, while Fisher's exact test works P out exactly from every table with the same row and column totals. This calculator runs both, and points to Fisher's when the counts are small.
What are the assumptions of the chi-square test?
The data are counts, not percentages or measurements; each individual is counted once, in one cell, so the observations are independent (counts before and after on the same people need McNemar's test instead); the categories don't overlap; and the expected counts are large enough, at least 5 in most cells and none below 1.
Critical values
Chi-square table
Each value is the χ² that leaves the area at the top of its column in the right-hand tail. Find the row for your degrees of freedom: if your χ² is at least the value under 0.05, then P < 0.05. The first five columns, for the left tail, test whether counts fit a ratio too well.
| df | 0.995 | 0.99 | 0.975 | 0.95 | 0.9 | 0.1 | 0.05 | 0.025 | 0.01 | 0.005 | 0.001 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 0.0000393 | 0.000157 | 0.000982 | 0.00393 | 0.0158 | 2.706 | 3.841 | 5.024 | 6.635 | 7.879 | 10.828 |
| 2 | 0.01 | 0.0201 | 0.0506 | 0.103 | 0.211 | 4.605 | 5.991 | 7.378 | 9.210 | 10.597 | 13.816 |
| 3 | 0.0717 | 0.115 | 0.216 | 0.352 | 0.584 | 6.251 | 7.815 | 9.348 | 11.345 | 12.838 | 16.266 |
| 4 | 0.207 | 0.297 | 0.484 | 0.711 | 1.064 | 7.779 | 9.488 | 11.143 | 13.277 | 14.860 | 18.467 |
| 5 | 0.412 | 0.554 | 0.831 | 1.145 | 1.610 | 9.236 | 11.070 | 12.833 | 15.086 | 16.750 | 20.515 |
| 6 | 0.676 | 0.872 | 1.237 | 1.635 | 2.204 | 10.645 | 12.592 | 14.449 | 16.812 | 18.548 | 22.458 |
| 7 | 0.989 | 1.239 | 1.690 | 2.167 | 2.833 | 12.017 | 14.067 | 16.013 | 18.475 | 20.278 | 24.322 |
| 8 | 1.344 | 1.646 | 2.180 | 2.733 | 3.490 | 13.362 | 15.507 | 17.535 | 20.090 | 21.955 | 26.124 |
| 9 | 1.735 | 2.088 | 2.700 | 3.325 | 4.168 | 14.684 | 16.919 | 19.023 | 21.666 | 23.589 | 27.877 |
| 10 | 2.156 | 2.558 | 3.247 | 3.940 | 4.865 | 15.987 | 18.307 | 20.483 | 23.209 | 25.188 | 29.588 |
| 11 | 2.603 | 3.053 | 3.816 | 4.575 | 5.578 | 17.275 | 19.675 | 21.920 | 24.725 | 26.757 | 31.264 |
| 12 | 3.074 | 3.571 | 4.404 | 5.226 | 6.304 | 18.549 | 21.026 | 23.337 | 26.217 | 28.300 | 32.909 |
| 13 | 3.565 | 4.107 | 5.009 | 5.892 | 7.042 | 19.812 | 22.362 | 24.736 | 27.688 | 29.819 | 34.528 |
| 14 | 4.075 | 4.660 | 5.629 | 6.571 | 7.790 | 21.064 | 23.685 | 26.119 | 29.141 | 31.319 | 36.123 |
| 15 | 4.601 | 5.229 | 6.262 | 7.261 | 8.547 | 22.307 | 24.996 | 27.488 | 30.578 | 32.801 | 37.697 |
| 16 | 5.142 | 5.812 | 6.908 | 7.962 | 9.312 | 23.542 | 26.296 | 28.845 | 32.000 | 34.267 | 39.252 |
| 17 | 5.697 | 6.408 | 7.564 | 8.672 | 10.085 | 24.769 | 27.587 | 30.191 | 33.409 | 35.718 | 40.790 |
| 18 | 6.265 | 7.015 | 8.231 | 9.390 | 10.865 | 25.989 | 28.869 | 31.526 | 34.805 | 37.156 | 42.312 |
| 19 | 6.844 | 7.633 | 8.907 | 10.117 | 11.651 | 27.204 | 30.144 | 32.852 | 36.191 | 38.582 | 43.820 |
| 20 | 7.434 | 8.260 | 9.591 | 10.851 | 12.443 | 28.412 | 31.410 | 34.170 | 37.566 | 39.997 | 45.315 |
| 21 | 8.034 | 8.897 | 10.283 | 11.591 | 13.240 | 29.615 | 32.671 | 35.479 | 38.932 | 41.401 | 46.797 |
| 22 | 8.643 | 9.542 | 10.982 | 12.338 | 14.041 | 30.813 | 33.924 | 36.781 | 40.289 | 42.796 | 48.268 |
| 23 | 9.260 | 10.196 | 11.689 | 13.091 | 14.848 | 32.007 | 35.172 | 38.076 | 41.638 | 44.181 | 49.728 |
| 24 | 9.886 | 10.856 | 12.401 | 13.848 | 15.659 | 33.196 | 36.415 | 39.364 | 42.980 | 45.559 | 51.179 |
| 25 | 10.520 | 11.524 | 13.120 | 14.611 | 16.473 | 34.382 | 37.652 | 40.646 | 44.314 | 46.928 | 52.620 |
| 26 | 11.160 | 12.198 | 13.844 | 15.379 | 17.292 | 35.563 | 38.885 | 41.923 | 45.642 | 48.290 | 54.052 |
| 27 | 11.808 | 12.879 | 14.573 | 16.151 | 18.114 | 36.741 | 40.113 | 43.195 | 46.963 | 49.645 | 55.476 |
| 28 | 12.461 | 13.565 | 15.308 | 16.928 | 18.939 | 37.916 | 41.337 | 44.461 | 48.278 | 50.993 | 56.892 |
| 29 | 13.121 | 14.256 | 16.047 | 17.708 | 19.768 | 39.087 | 42.557 | 45.722 | 49.588 | 52.336 | 58.301 |
| 30 | 13.787 | 14.953 | 16.791 | 18.493 | 20.599 | 40.256 | 43.773 | 46.979 | 50.892 | 53.672 | 59.703 |
| 40 | 20.707 | 22.164 | 24.433 | 26.509 | 29.051 | 51.805 | 55.758 | 59.342 | 63.691 | 66.766 | 73.402 |
| 50 | 27.991 | 29.707 | 32.357 | 34.764 | 37.689 | 63.167 | 67.505 | 71.420 | 76.154 | 79.490 | 86.661 |
| 60 | 35.534 | 37.485 | 40.482 | 43.188 | 46.459 | 74.397 | 79.082 | 83.298 | 88.379 | 91.952 | 99.607 |
| 70 | 43.275 | 45.442 | 48.758 | 51.739 | 55.329 | 85.527 | 90.531 | 95.023 | 100.425 | 104.215 | 112.317 |
| 80 | 51.172 | 53.540 | 57.153 | 60.391 | 64.278 | 96.578 | 101.879 | 106.629 | 112.329 | 116.321 | 124.839 |
| 90 | 59.196 | 61.754 | 65.647 | 69.126 | 73.291 | 107.565 | 113.145 | 118.136 | 124.116 | 128.299 | 137.208 |
| 100 | 67.328 | 70.065 | 74.222 | 77.929 | 82.358 | 118.498 | 124.342 | 129.561 | 135.807 | 140.169 | 149.449 |
Worked out to full precision and rounded to 3 decimals, or 3 significant figures below 1. For another df or α, use the P value mode above.
More Calculators
Each one shows its formula and a worked example, so you can check the answer and learn the method.
Sample Size and Power Calculator
How many participants a survey or a two-group study needs, or the power of the sample you have, with a paragraph for your methods.
Open calculatorHardy-Weinberg Equation Calculator
Solve p² + 2pq + q² = 1 from any one frequency with the working shown, or test genotype counts for equilibrium by chi-square and the exact test.
Open calculatorDihybrid Cross Calculator
The Punnett square for any cross of two genes, with the gametes, the genotype and phenotype ratios, gene interactions and a chi-square test of your counts.
Open calculatorPractice the theory with free quizzes in Epidemiology, Genetics, Public Health, Medicine and Ecology.