How it’s calculated
The chi-square test compares observed counts with the counts you would expect if the null hypothesis were true. The bigger the gaps, the bigger χ² and the smaller the p-value.
Goodness of fit asks whether one set of counts matches a claimed distribution, such as a fair die or a genetic ratio. Leave "expected" empty for equal counts, or enter proportions or a ratio; they are scaled to your total. Independence asks whether two categorical variables (the rows and columns of a table) are related. The test needs expected counts of at least 5 in (most) cells, and the calculator warns when they are smaller. It uses the standard Pearson formula with no Yates continuity correction, even for 2 × 2 tables.
Example (Mendel's peas, ratio 9:3:3:1): observed 315, 108, 101, 32, total 556, so the expected counts are 312.75, 104.25, 104.25, 34.75. χ² = 2.25²/312.75 + 3.75²/104.25 + 3.25²/104.25 + 2.75²/34.75 = 0.470 with 3 degrees of freedom, p = 0.925. That is well above 0.05, so the data fit the 9:3:3:1 ratio. As a check on the tables, χ² = 3.841 with 1 degree of freedom gives p ≈ 0.05.
Frequently asked questions
What does the p-value tell me?
It is the chance of seeing counts at least this far from the expected ones if the null hypothesis (the counts follow the expected pattern, or the two variables are unrelated) were true. A p-value below your α, usually 0.05, is evidence against it.
What if some expected counts are below 5?
The chi-square approximation becomes unreliable. Combine neighbouring categories, collect more data, or for a 2 × 2 table consider an exact test. The calculator flags this under "Expected-count check".
How are the degrees of freedom worked out?
Goodness of fit has (categories − 1). A test of independence has (rows − 1) × (columns − 1). If you estimated parameters of the distribution from the same data, subtract one more for each parameter; this calculator does not do that automatically.
Does this use a continuity correction (Yates) for 2 × 2 tables?
No. The χ² shown is the standard Pearson statistic with no Yates continuity correction. For a 2 × 2 table with small counts the correction (or an exact test) can give a somewhat larger p-value.
Can I enter percentages or proportions as the expected values?
Yes. Expected values are treated as relative weights and scaled to the total of the observed counts, so 25, 25, 25, 25 and 1, 1, 1, 1 both mean "equal". Observed values must be actual counts, not percentages.
Embed this calculator
Add this free calculator to your own website. Copy the code below into your page’s HTML:
Need this calculator branded, changed or built around your own prices?See custom business solutions →
Sources
- Introductory Statistics 2e, §11.2 Goodness-of-Fit Test — OpenStax
- Introductory Statistics 2e, §11.3 Test of Independence — OpenStax
- NIST/SEMATECH e-Handbook of Statistical Methods, 1.3.6.7.4 Critical Values of the Chi-Square Distribution — NIST
- NIST/SEMATECH e-Handbook of Statistical Methods, 1.3.5.15 Chi-Square Goodness-of-Fit Test — NIST
Formulas are taken from the free public references above. Results are provided “as is” for informational and educational purposes only. See our disclaimer.
Added · Last updated · How we check our calculators
Spotted a mistake or missing option? Report a problem· Suggest a calculator