How to use it
- Choose Test: independence in a table, or goodness of fit to expected shares.
- For independence, type the Table of counts, one row per line. For goodness of fit, type the Observed counts and, if you have them, the Expected weights.
- Choose the Significance level α, usually 5%.
- Read Conclusion at α, then Chi-square statistic χ², the p-value and the Expected counts, cell by cell.
How the chi-square statistic is calculated
For each cell the expected count is what H₀ predicts. For a table, H₀ says that rows and columns are independent, so the expected count of a cell is its row total times its column total, divided by the grand total. For a goodness-of-fit test, the expected count of a category is the total times its share of the expected weights.
The statistic adds up (observed − expected)² ÷ expected over all cells. The larger it is, the less the counts look like the expected pattern. Its p-value comes from the chi-square distribution with the degrees of freedom shown: (rows − 1) × (columns − 1) for a table, and the number of categories minus one for a fit, because no parameter is estimated from the data.
expected (independence) = row total × column total ÷ N
expected (fit) = N × weight ÷ sum of weights
χ² = Σ (observed − expected)² ÷ expected
df = (rows − 1)(columns − 1), or categories − 1
When the result is not reliable
The chi-square distribution is an approximation that works when the expected counts are not too small. The calculator warns when any expected count is below 5, and says how many cells are affected. Cochran's rule (1952) is stricter: no expected count below 1, and at most a fifth of them below 5. If the rule fails, combine small categories or use an exact test such as Fisher's.
What the calculator does not cover
- Paired or matched categories, which need McNemar's test, and tables where the same subject appears in several cells.
- Exact tests for small samples, such as Fisher's exact test, and trend tests for ordered categories.
- Comparisons of means: use the t-test calculator for those, and the statistics calculator to inspect the data.
Worked example: Mendel's pea counts against 9:3:3:1
Mendel's counts of 315, 108, 101 and 32 peas in four classes have expected counts of 312.75, 104.25, 104.25 and 34.75 for the 9:3:3:1 ratio. The statistic is χ² = 0.4700 with 3 degrees of freedom, and the p-value is 0.9254, so the ratio is not rejected.
R's table of hair and eye colour (summed over the sexes) gives χ² = 138.29 with 9 degrees of freedom and a p-value below 0.0001: hair colour and eye colour are associated.
| Class | Observed | Expected |
|---|---|---|
| Round, yellow | 315 | 312.75 |
| Wrinkled, yellow | 108 | 104.25 |
| Round, green | 101 | 104.25 |
| Wrinkled, green | 32 | 34.75 |
Frequently asked questions
What is the difference between a test of independence and a goodness-of-fit test?
A test of independence asks whether two categorical variables in a table are related. A goodness-of-fit test asks whether one set of counts matches expected shares, such as a genetic ratio or a known population mix.
Why are the degrees of freedom (rows − 1) × (columns − 1)?
Once the row and column totals are fixed, only (rows − 1) × (columns − 1) of the cells can be chosen freely; the rest follow from the totals. Those free cells are the degrees of freedom.
What do the expected counts tell me?
They are the counts you would see in each cell if the null hypothesis were true. Comparing them cell by cell shows where the observed counts differ most, and the contribution column points to the largest differences.
What should I do when some expected counts are below 5?
Merge small categories where that makes sense, collect more data, or use Fisher's exact test for a two-by-two table. The p-value of the chi-square test is then less trustworthy.
Can I use the test for percentages or measurements?
Use it on counts, not on percentages or measured values. Convert percentages back to counts with the sample size, and use a t test for means of continuous measurements.
Does the calculator send my numbers anywhere?
No. The calculation runs in your browser, and nothing you type is sent to our servers.
Sources
- NIST/SEMATECH e-Handbook of Statistical Methods, 1.3.5.15: Chi-square goodness-of-fit test
- NIST/SEMATECH e-Handbook of Statistical Methods, 1.3.6.7: Tables for probability distributions
- Wikipedia: Chi-squared test (independence and goodness of fit)
Figures and text last checked on Tuesday, November 10, 2026.