Chi-Square Test Calculator
Chi-square test for independence or goodness of fit
We use cookies for analytics and advertising. Learn more about our cookie policy
Last updated: 23 August 2026
Reviewed by Gavin Meiring, Lead research and primary author · Doctoral Candidate (Corporate Governance) · Research and drafting assisted by AI
Chi-square test for independence or goodness of fit
The chi-square test calculator computes the chi-square statistic, degrees of freedom, and p-value for goodness-of-fit tests and tests of independence. It is used by statisticians analysing categorical data, by biologists testing Mendelian ratios, by sociologists comparing survey responses across groups, by market researchers testing whether customer preferences differ, by quality engineers checking manufacturing defect patterns, by epidemiologists analysing case-control studies, and by students learning hypothesis testing. The chi-square test is one of the most commonly applied statistical tests because it handles categorical data, the kind that arises whenever you count things and put them in bins.
Chi-square statistic:
χ² = Σ ((Oᵢ − Eᵢ)² / Eᵢ)
Where:
Degrees of freedom:
For goodness-of-fit: df = k − 1 (where k is the number of categories), adjusted if any parameters are estimated from the data.
For independence (r × c contingency table): df = (r − 1) × (c − 1).
P-value: the probability of observing a chi-square statistic this large or larger, given the null hypothesis is true. The chi-square distribution is the relevant reference; the calculator uses the upper tail of this distribution.
Example 1, Goodness-of-fit (Mendelian genetics)
A geneticist crosses two heterozygous pea plants (Rr × Rr). The expected ratio is 3:1 (round to wrinkled). Of 100 offspring, 73 are round and 27 are wrinkled.
Expected: 75 round, 25 wrinkled.
χ² = (73 − 75)² / 75 + (27 − 25)² / 25 = 4/75 + 4/25 = 0.053 + 0.160 = 0.213
df = 1 P-value ≈ 0.645 (very high, no evidence against the 3:1 ratio)
Example 2, Goodness-of-fit (dice)
A die is rolled 60 times. Observed counts: 1→12, 2→8, 3→10, 4→9, 5→11, 6→10.
Expected if fair: 10 per face.
χ² = (12−10)²/10 + (8−10)²/10 + (10−10)²/10 + (9−10)²/10 + (11−10)²/10 + (10−10)²/10 = 4/10 + 4/10 + 0 + 1/10 + 1/10 + 0 = 1.0
df = 5 P-value ≈ 0.963 (very high, no evidence the die is unfair)
Example 3, Test of independence (contingency table)
A researcher surveys 200 people about exercise habits and smoking status:
| Smoker | Non-smoker | Total | |
|---|---|---|---|
| Exercise regularly | 30 | 70 | 100 |
| Don't exercise | 50 | 50 | 100 |
| Total | 80 | 120 | 200 |
Expected counts (under independence): row total × column total / grand total.
E₁₁ = 100 × 80 / 200 = 40 (smokers who exercise) E₁₂ = 100 × 120 / 200 = 60 E₂₁ = 100 × 80 / 200 = 40 E₂₂ = 100 × 120 / 200 = 60
χ² = (30−40)²/40 + (70−60)²/60 + (50−40)²/40 + (50−60)²/60 = 100/40 + 100/60 + 100/40 + 100/60 = 2.5 + 1.667 + 2.5 + 1.667 = 8.333
df = (2−1)(2−1) = 1 P-value ≈ 0.0039 (significant at α = 0.01, strong evidence of association between exercise and smoking)
Example 4, Independence with 3×3 table
A clinical trial measures treatment outcomes across three age groups:
| Improved | No change | Worsened | Total | |
|---|---|---|---|---|
| Under 30 | 25 | 15 | 10 | 50 |
| 30-60 | 30 | 30 | 20 | 80 |
| Over 60 | 15 | 25 | 30 | 70 |
| Total | 70 | 70 | 60 | 200 |
df = (3−1)(3−1) = 4 Computing expected counts and chi-square gives χ² ≈ 14.5, p-value ≈ 0.006. Strong evidence that treatment outcomes differ by age group.
The chi-square test requires:
When expected counts are too small, use Fisher's exact test for 2×2 tables or exact tests for larger tables.
Goodness-of-fit: Does observed data fit an expected distribution? (e.g., Mendelian ratios, die fairness, market share predictions, survey responses vs. hypothesised proportions)
Test of independence: Are two categorical variables associated? (e.g., smoking × disease, treatment × outcome, education × voting preference)
Homogeneity: Are multiple samples drawn from the same distribution? (Similar to independence but with pre-defined groups)
Using chi-square for small samples. With expected counts < 5, the chi-square approximation breaks down. Use Fisher's exact test or combine categories.
Confusing goodness-of-fit with independence. They are different tests with different hypotheses. The first tests fit to a distribution; the second tests association between variables.
Reporting "significant" without effect size. A statistically significant chi-square doesn't tell you how strong the association is. Report Cramér's V or phi coefficient for effect size.
Multiple testing. Running chi-square tests on many variables inflates the false positive rate. Use Bonferroni or other corrections.
Forgetting to convert to counts. Chi-square requires frequency data, not percentages or proportions. Convert percentages to counts by multiplying by sample size.
What does chi-square measure? The discrepancy between observed and expected counts. Larger values indicate greater departure from the null hypothesis.
Who developed the chi-square test? Karl Pearson published the chi-square test in 1900. Earlier work by Helmert and others laid the foundation.
What is the chi-square distribution? The distribution of the sum of squared standard normal variables. With k degrees of freedom, it has mean k and variance 2k. As df increases, it approaches normality.
What is a "significant" chi-square? It depends on df. For df = 1, χ² > 3.84 is significant at α = 0.05. For df = 5, the threshold is 11.07. The calculator computes p-values directly.
What is Fisher's exact test? A non-parametric test for 2×2 contingency tables that works well for small samples. It computes the exact probability of observing the data (or more extreme) under the null hypothesis.
What is Cramér's V? A measure of association strength based on chi-square: V = √(χ² / (n × min(r−1, c−1))). Ranges from 0 (no association) to 1 (perfect association).
Can I use chi-square for continuous data? Not directly. Chi-square works on categorical (count) data. For continuous data, consider t-tests, ANOVA, or non-parametric tests.
Why are expected counts important? The chi-square statistic and its p-value assume expected counts are reasonably large. With small counts, the test gives unreliable results.
Q: can the Chi-Square Test Calculator be used for professional or commercial purposes? A: yes, the Chi-Square Test Calculator The Chi-Square Test Calculator provides mathematically correct results that are suitable for professional, commercial, and educational use. the Chi-Square Test Calculator formulas used are well-established and validated against reference standards.
Q: How often are the formulas behind the Chi-Square Test Calculator updated? When standards change (e.g., new physical constants, revised tax brackets, updated standards), the Chi-Square Test Calculator is updated to reflect the current authoritative source. Each calculator's references section, including the Chi-Square Test Calculator, lists the specific sources used.
Each field on the Chi-Square Test Calculator form plays a distinct part in the calculation.
The errors that come up most often with the Chi-Square Test Calculator are easy to spot once you know them:
Use the Chi-Square Test Calculator whenever you need a quick, reliable answer that fits the tool's scope. Common situations for the Chi-Square Test Calculator include homework and study, on-the-job quick checks, sanity-checking a more complex calculation, or exploring a scenario for personal interest. If the Chi-Square Test Calculator answer will be used for a decision that has legal, medical, or financial consequences, treat the result as a starting point and verify it with a qualified professional.
The calculation behind the Chi-Square Test Calculator follows the standard form for this kind of problem: Chi-square statistic:** χ² = Σ ((Oᵢ − Eᵢ)² / Eᵢ)** Where: Oᵢ** is the observed count in category i Eᵢ** is the expected count under the null hypothesis The sum is over all categories Degrees of freedom:** For goodness-of-fit: df = k − 1 (wh The Chi-Square Test Calculator applies that relationship in the order the algebra prescribes, converting inputs to consistent units first where the formula needs them.
The Chi-Square Test Calculator fits alongside the other tools in its category, and the choice between them usually comes down to which inputs you already have. If the same numbers feed several tools, run them in one pass so the assumptions stay consistent across the comparison, which is where the Chi-Square Test Calculator earns its place.
A typical Chi-Square Test Calculator run takes reasonable inputs, produces a sensible answer, and returns it in a single click. Example: Example 1, Goodness-of-fit (Mendelian genetics) A geneticist crosses two heterozygous pea plants (Rr × Rr). The expected ratio is 3:1 (round to wrinkled). Of 100 offspring, 73 are round and 27 are wrinkled. Expected: 75 round, 25 wrinkled. χ² = (73 − 75)² / 75 + (27 − 25)² / 25 = 4/75 + 4/25 = 0.053 + 0.160 = 0.213 df = 1 P-value ≈ 0.645 (very high, no evidence against the 3:1 ratio) **Exa