Chi-Square Test Calculator
Paste a table of counts. See the chi-square test, the expected counts and the effect size.
https://flxcode.com/chi-square-test-calculator/
Paste a table of counts from Excel, Google Sheets or a CSV file: one row per line, one column per category. A header row and a first column of names are picked up. Names with spaces need a tab or comma after them. 2 × 2 up to 10 × 10.
The correction changes the headline only when the table is 2 × 2.
Example Chi-square test of independence
Evidence of an association at the 5% level
Read a 2 × 3 table of counts, 200 in total, with a header row and row names.
Observed counts, with totals
| Row | Dog | Cat | None | Total |
|---|---|---|---|---|
| House | 45 | 35 | 20 | 100 |
| Apartment | 25 | 40 | 35 | 100 |
| Total | 70 | 75 | 55 | 200 |
Expected counts if the categories were unrelated
| Row | Dog | Cat | None |
|---|---|---|---|
| House | 35 | 37.5 | 27.5 |
| Apartment | 35 | 37.5 | 27.5 |
Standardized residuals: (observed − expected) ÷ √expected
| Row | Dog | Cat | None |
|---|---|---|---|
| House | 1.69 | -0.408 | -1.43 |
| Apartment | -1.69 | 0.408 | 1.43 |
Contribution of each cell to the chi-square
| Row | Dog | Cat | None |
|---|---|---|---|
| House | 2.857 | 0.1667 | 2.045 |
| Apartment | 2.857 | 0.1667 | 2.045 |
Cells marked * in the residuals table have a standardized residual beyond ±1.96: they differ from the expected count more than chance alone usually does, and they are where the association comes from.
| Chi-square (Pearson) | 10.1385 |
|---|---|
| Degrees of freedom | 2 |
| p-value (Pearson) | 0.00628705 |
| Total count (n) | 200 |
| Cramér’s V | 0.2252, small |
| Smallest expected count | 27.5 |
| Cells with an expected count below 5 | 0 of 6 (0%) |
The steps, with your numbers
Expected count of a cell = row total × column total ÷ grand total. For House and Dog: 100 × 70 ÷ 200 = 35.
Each cell adds (observed − expected)² ÷ expected. Added up: 2.857 + 0.1667 + 2.045 + 2.857 + 0.1667 + 2.045 = 10.1385.
Degrees of freedom = (rows − 1) × (columns − 1) = 1 × 2 = 2.
p-value = the chance of a chi-square of 10.139 or more with 2 degrees of freedom, if the two categories were unrelated = 0.00628705.
Cramér’s V = √(chi-square ÷ (n × 1)) = √(10.139 ÷ (200 × 1)) = 0.2252. For a 2 × k table small starts at 0.1, medium at 0.3, large at 0.5.
No ads. No account. Nothing you type or record is uploaded. We count page events with a daily code. Check it. What this tool keeps and sends.
Problem or idea? Email us
Quick start
- Paste a table of counts, one row per line. Put the names of the columns in the first row and the names of the rows in the first column if you have them.
- The headline gives chi-square, the degrees of freedom and p. Under it you get the observed and expected counts, the residuals and each cell's share of the total.
- For one column of counts against expected shares, switch to Goodness of fit.
Worked examples
| Case | Data | Chi-square | df | p | Note |
|---|---|---|---|---|---|
| Housing and pet | 2 × 3 table: house or apartment against dog, cat or none, 200 people | 10.139 | 2 | 0.00628705 | Cramér’s V 0.225 |
| A 2 × 2 table, Pearson | 12 and 5 in the top row, 7 and 16 in the bottom | 6.3199 | 1 | 0.0119391 | No correction |
| The same table, Yates | Each difference is reduced by 0.5 first | 4.8123 | 1 | 0.0282575 | What R prints by default |
| Tiny counts | 3 and 1 in the top row, 1 and 3 in the bottom | 2 | 1 | 0.157299 | All 4 cells have an expected count below 5: use an exact test |
| Customers by weekday | 38, 24, 29, 31 and 48 customers, expected equal | 10.176 | 4 | 0.0375577 | Friday is the odd one out |
| Counts against shares | Red 40, blue 40, green 70 against shares of 20%, 30% and 50% | 4.2222 | 2 | 0.121103 | The shares are scaled to the total of 150 |
The tiny-count table gives p = 0.157299 here, but the exact answer is quite different. See the Fisher exact test calculator for that table.
The formulas
The expected count of a cell is E = row total × column total / n. The statistic adds one term per cell: χ² = Σ (O − E)² / E. The degrees of freedom are (rows − 1) × (columns − 1) for a table and categories − 1 for goodness of fit. The p-value is the upper tail of the chi-square distribution, computed with the incomplete gamma function, so very small values keep their digits.
Cramér's V is √(χ² / (n × min(rows − 1, columns − 1))). The Yates correction replaces |O − E| with max(0, |O − E| − 0.5) in a 2 × 2 table. To get a p-value from a chi-square you already have, use the p-value calculator.
Excel and Google Sheets
Put the counts in B2:D3 with the names in row 1 and column A, as the download does. Excel and Google Sheets give only the p-value, and you build the expected table by hand.
| Cell | Formula | Gives |
|---|---|---|
| Expected count | =SUM($B2:$D2)*SUM(B$2:B$3)/SUM($B$2:$D$3) | 27.5 for the smallest cell |
| p-value | =CHISQ.TEST(B2:D3, expected) | 0.00628705 |
| Statistic | =SUMPRODUCT((B2:D3-expected)^2/expected) | 10.1385 |
| p from the statistic | =CHISQ.DIST.RT(stat, 2) | 0.00628705 |
| Critical value at 0.05 | =CHISQ.INV.RT(0.05, 2) | 5.99146 |
| Cramér's V | =SQRT(stat/(n*MIN(rows-1,cols-1))) | 0.2252 |
Goodness of fit works the same way with one column: =CHISQ.TEST(observed, expected). Download .xlsx writes your counts, the expected table and these formulas with your numbers, so editing a count updates everything.
Numbers this uses
- Default test is Pearson. Yates is one chip away for 2 × 2 tables.
- Accuracy is matches scipy to 9 digits or better. Checked on 300 random tables up to 10 × 10 and 100 goodness-of-fit cases.
- Limits is 10 × 10 table, 100 categories. Whole-number counts up to 1,000,000,000 per cell.
Limits
Counts must be whole numbers, not percents or averages, and every row and column needs at least one count above 0. The test assumes each observation is counted once and the observations are independent: it does not suit before-and-after counts on the same people. It says that the categories are related, not why. There is no trend test for ordered categories.
FAQ
What does a chi-square test tell me?
For a table, whether two categories look related: whether the share of one category changes across the other. For a single column, whether your counts fit the shares you expected. The p-value is the chance of a gap this large or larger if nothing were going on.
Independence or goodness of fit?
Independence takes a table: two ways of classifying the same people or things, like housing and pet. Goodness of fit takes one column of counts and compares it with expected shares, like customers per weekday against an even spread (p = 0.0375577 for the example).
What are expected counts?
What each cell would hold if the two categories were unrelated: row total × column total ÷ grand total. The test measures how far your counts are from them. Small expected counts make the p-value unreliable, so the page counts the cells below 5.
Pearson or Yates?
Pearson is the plain test, and the headline here. Yates reduces each difference by 0.5 for 2 × 2 tables, which makes the p-value larger and safer when counts are small. On the 2 × 2 example above they give p = 0.0119391 and 0.0282575. R applies Yates by default to 2 × 2 tables (its chisq.test help says so), so the same table can give two answers in two programs. Many statisticians now think Yates is too cautious.
What if some expected counts are below 5?
The usual rule is that no cell should be below 1 and at most 20% below 5. If you break it, combine categories, collect more data, or for a 2 × 2 table use the Fisher exact test on this site, which has no such rule.
What are the residuals?
A standardized residual is (observed − expected) ÷ √expected for one cell. Beyond about ±2 (the page marks 1.96) the cell is one of the places where the counts differ from the expected. They show where the association comes from, not just that there is one.
More from FLXCode
- Fisher Exact Test CalculatorFisher exact test for a 2x2 table: two-sided and one-sided p-values and the odds ratio.
- P-Value Calculatorp-value from a z, t, chi-square or F statistic, one or two tailed, with the tails shown.
- T-Test CalculatorOne-sample, Welch, Student and paired t-tests from raw data or summary numbers, with p, CI and d.
- Z-Score Calculatorz-score from a value, mean and standard deviation, or from data, with percentile and p-values.