Chi Square Calculator
Run a chi-square goodness-of-fit test from observed and expected counts: get the chi-square statistic, degrees of freedom and p-value for Mendelian ratios
Chi Square Calculator
Calculator
Adjust values & calculateEnter your values below. Every result is computed in your browser — no data is sent to any server.
Formula: χ² = Σ[(Oᵢ - Eᵢ)² / Eᵢ] | df = k - 1 (goodness-of-fit)
Worked example — χ² = 14.00, df = 2, p ≈ 0.0009 — Significant (not fair)
Formula
χ² = Σ[(Oᵢ - Eᵢ)² / Eᵢ] | df = k - 1 (goodness-of-fit)
The chi-square goodness-of-fit test compares observed counts (O) in each category with the counts expected (E) under a hypothesis, summing (O - E)² / E across all k categories. A large χ² relative to the chi-square distribution with k - 1 degrees of freedom gives a small p-value and means the observed counts differ significantly from expectation. If no expected values are given, the calculator assumes an equal split across categories.
Worked Examples
Example 1: Dice fairness test
Problem:Roll dice 100 times: 50, 30, 20 for three outcomes (expected: 33.3 each)
Solution:χ² = (50-33.33)²/33.33 + (30-33.33)²/33.33 + (20-33.33)²/33.33 = 8.33 + 0.33 + 5.33 = 14.00
Result:χ² = 14.00, df = 2, p ≈ 0.0009 — Significant (not fair)
Example 2: Mendelian 3:1 monohybrid ratio
Problem:A cross between two heterozygous pea plants gives 160 offspring: 130 tall and 30 short. Do the counts fit the expected 3:1 ratio?
Solution:Expected: 160 x 3/4 = 120 tall, 160 x 1/4 = 40 short (enter 120,40 in the expected field) χ² = (130-120)²/120 + (30-40)²/40 = 100/120 + 100/40 = 0.833 + 2.500 = 3.333 df = 2 - 1 = 1; critical value at α = 0.05 is 3.841 p ≈ 0.068
Result:χ² = 3.33, df = 1, p ≈ 0.068 — Not significant; the data are consistent with a 3:1 ratio
Frequently Asked Questions
When do I use the chi-square test?
Use chi-square for: (1) Goodness-of-fit: observed frequencies match expected distribution? (2) Independence: are two categorical variables related? Requires expected counts ≥ 5 per cell.
What are the assumptions?
Data must be frequencies (counts), not percentages. Observations must be independent. Expected frequency should be ≥ 5 per category (use Fisher's exact test for small samples).
What is the difference between chi-square goodness-of-fit and chi-square test of independence?
The goodness-of-fit test uses a single sample and one categorical variable to test whether observed frequencies match a theoretically expected distribution, such as testing if a die is fair. The test of independence uses a two-way contingency table with two categorical variables from the same sample and tests whether the two variables are associated with each other, such as whether smoking status is associated with disease outcome. Both tests use the same chi-square formula but have different degrees of freedom calculations and different research questions.
How do I interpret a chi-square p-value?
The p-value in a chi-square test represents the probability of observing a chi-square statistic at least as extreme as the one calculated, assuming the null hypothesis is true. A p-value below your significance level (typically 0.05) means you reject the null hypothesis. For a goodness-of-fit test, rejecting the null means the data does not follow the expected distribution. For a test of independence, rejecting the null means the two variables are statistically associated. A p-value of 0.03 means there is only a 3% chance of getting such extreme results if the null were true — low enough to consider the result significant at the 5% level.
How are the degrees of freedom determined for a chi-square test?
For a goodness-of-fit test on k categories, df = k - 1, because the category counts are constrained to sum to the observed total. Subtract one further degree of freedom for every parameter you estimated from the same data. For an r-by-c contingency table, df = (r - 1)(c - 1), since the row and column marginal totals are fixed. Degrees of freedom set the shape of the reference distribution, so getting them wrong shifts both the critical value and the p-value.
What is Yates's continuity correction and when should it be applied?
Yates's correction subtracts 0.5 from each absolute deviation before squaring, giving a statistic of sum over cells of (|O - E| - 0.5) squared divided by E. It applies only to 2-by-2 contingency tables with 1 degree of freedom, where a discrete distribution of counts is being approximated by a continuous curve. The correction shrinks the statistic and makes the test more conservative, reducing false positives in small tables but proving overly cautious once counts are large.
How do I test a Mendelian 9:3:3:1 dihybrid ratio with Chi Square Calculator?
Enter the four observed phenotype counts, then type the expected counts explicitly rather than leaving that field blank, because the default assumes an equal split across categories. Divide the total offspring by 16 and multiply by 9, 3, 3 and 1 in turn. For 160 offspring that gives expected counts of 90, 30, 30 and 10. Four categories means 3 degrees of freedom, so the 0.05 critical value is 7.815.
Why must a chi-square test be computed on raw counts rather than percentages?
The statistic scales directly with sample size: hold the proportions fixed but multiply every count by ten and chi-square also multiplies by ten. Sample size is exactly the information that tells you whether a deviation is meaningful, and converting to percentages throws it away. Entering 50, 30 and 20 as percentages silently forces the calculation to behave as though only 100 observations were collected, understating the evidence from a large study and overstating it from a small one.
Which effect size should accompany a significant chi-square result?
Chi-square tests only whether a departure from expectation exists, not how large it is, and with a big enough sample almost any trivial departure reaches significance. For a 2-by-2 table report the phi coefficient, the square root of chi-square divided by n. For larger tables report Cramer's V, the square root of chi-square divided by n times the smaller of (r - 1) and (c - 1). Both range from 0 to 1 and describe association strength independently of sample size.
How does a chi-square test of Hardy-Weinberg equilibrium differ from an ordinary goodness-of-fit test?
The expected genotype counts are not known in advance. You estimate the allele frequency p from the same genotype data, set q = 1 - p, then multiply p squared, 2pq and q squared by the number of individuals. Because one parameter was estimated from the data, a biallelic locus with three genotype classes carries 3 - 1 - 1 = 1 degree of freedom rather than 2. Using df = 2 makes the test far too lenient and hides genuine departures from equilibrium.
References
Background & Theory
History
Reviewed for accuracy by Daniel Agrici, Founder & Lead Developer · Editorial policy
Related Calculators
🧮Dihybrid Cross Punnett Square Calculator
Calculate dihybrid cross punnett square with inputs, formulas, and instant results.
🧮Punnett Square Calculator: Genotype & Phenotype Odds
Calculate punnett square with inputs, formulas, and instant results.
🧮Trihybrid Cross Punnett Square Calculator
Calculate trihybrid cross punnett square with inputs, formulas, and instant results.
🧮Alpaca Gestation Calculator
Calculate alpaca gestation with inputs, formulas, and instant results.
🧮Cat Pregnancy Calculator — Due Date & Gestation
Calculate cat pregnancy with inputs, formulas, and instant results.
🧮Cow Gestation Calculator
Calculate cow gestation with inputs, formulas, and instant results.
🧮Dog Pregnancy Calculator: Due Date by Breed
Calculate dog pregnancy with inputs, formulas, and instant results.
🧮Goat Gestation Calculator
Calculate goat gestation with inputs, formulas, and instant results.