The Chi-Squared Goodness-of-Fit Test
A cross of two pea plants yields 580 progeny: 432 purple flowers, 148 white. Is this consistent with a simple 3:1 Mendelian ratio? Or is something else going on — linked genes, reduced viability, an extra locus, incomplete penetrance? The naive answer, "432/580 ≈ 74.5%, close enough to 75%," is not science. It is a guess dressed up as a conclusion. Genetics needs a rule that converts "close enough" into a number with a defined meaning. That way, two scientists looking at the same data will agree on whether it supports a hypothesis. The chi-squared (χ²) goodness-of-fit test supplies exactly that rule. It takes an observed set of counts, and a hypothesis that predicts expected counts. It returns a single statistic that measures how far the data deviate from expectation. This is scaled by how much deviation is plausible from chance sampling alone. Attached to that statistic is a probability — the p-value. It answers a precise question: if the hypothesis were true, and nothing but chance were operating, how often would we see deviation this large or larger? This matters because Mendelian ratios are never observed as exact fractions in real crosses. Meiosis is a random process, gametes fuse randomly, and litter or seed sizes are finite. Even a perfect 3:1 hypothesis will rarely produce exactly 75.00% purple offspring. This holds true in any single experiment of finite size. Sampling error guarantees wobble around the true ratio. The chi-squared test is the tool geneticists use to decide something important. They decide whether observed wobble is the kind chance alone produces. Or whether it signals a real biological deviation such as linkage, lethality, or an extra segregating gene. This article builds the test from its statistical foundations up through the full worked calculation. It shows the historical dispute it helped resolve. This includes the still-debated question of whether Mendel's own data were "too good." It gives two complete worked crosses so that the logic becomes second nature — not just the arithmetic. It assumes familiarity with Probability Rules in Genetics. It also sets up the reasoning later used in Complementation Analysis, where statistical tests again separate real genetic signal from noise.
- The chi-squared goodness-of-fit test compares observed genetic ratios to those predicted by a hypothesis (e.g., 3:1, 9:3:3:1) and produces a single statistic summarizing the mismatch.
- The formula is χ² = Σ (O − E)²/E, summed across all phenotypic or genotypic classes.
- Degrees of freedom = (number of classes − 1); this, with χ², gives a p-value from the chi-squared distribution.
- A p-value below the conventional threshold of 0.05 means the deviation is unlikely to be due to chance alone, so the hypothesis is rejected.
- The test cannot prove a hypothesis true — it can only fail to reject it; large samples make even trivial deviations "significant."
- Karl Pearson's 1900 statistic, later reinterpreted through R.A. Fisher's critique of Mendel's data ("too good to be true"), shaped how modern genetics judges evidence.
The chi-squared test converts the vague feeling that data "look off" from a genetic hypothesis into a quantitative probability, letting geneticists distinguish real biological deviation from ordinary sampling chance.
The core idea
The chi-squared goodness-of-fit test is a statistical procedure for evaluating whether observed frequency data are consistent with a specific, quantitatively stated hypothesis. In transmission genetics, that hypothesis is usually a Mendelian segregation ratio — 3:1 for a monohybrid cross, 1:1 for a testcross, 9:3:3:1 for an independently assorting dihybrid cross, or some modified ratio (9:7, 9:3:4, 15:1) predicted by epistasis or gene interaction. The test does not ask "do the observed numbers exactly match the expected numbers?" — they almost never will, because Mendelian ratios describe probabilities of individual fertilization events, and any finite sample of offspring is subject to sampling error (chance deviation from a true underlying probability, shrinking in relative size as sample size grows, per the Law of Large Numbers). Instead, the chi-squared test asks a conditional-probability question, precisely the kind of reasoning built on Probability Rules in Genetics: assuming the null hypothesis is exactly true, what is the probability of observing a deviation from expectation at least as large as the one actually observed, due to chance sampling alone? This probability is the p-value. If the p-value is small (conventionally, below 0.05), the observed data are judged too improbable under the null hypothesis for that hypothesis to be comfortably retained, and it is rejected. If the p-value is not small, the data are consistent with — never "proven equal to" — the null hypothesis, and the null hypothesis is not rejected. Three components make up the machinery: the chi-squared statistic itself (a number computed from observed and expected counts), the degrees of freedom (a parameter describing how many classes were free to vary once totals and expected proportions were fixed), and the p-value (looked up from the chi-squared probability distribution, which is itself a family of curves indexed by degrees of freedom). Understanding how these three fit together — not just plugging numbers into a formula — is the actual content of this technique, and it is what separates a student who can defend a genetic conclusion from one who can only recite an equation.
Mechanism
Step 1 — State the null hypothesis (H₀) as a ratio of expected proportions. For a monohybrid F₁ × F₁ cross of a simple dominant trait, H₀ is that offspring segregate 3 dominant : 1 recessive. For a dihybrid cross with independent assortment, H₀ is 9:3:3:1 across four phenotypic classes. The hypothesis must be quantitative and falsifiable — "purple is dominant" is not testable by chi-squared; "3/4 of offspring will be purple" is.
Step 2 — Calculate expected numbers (E) from the total sample size (n). Multiply n by each hypothesized proportion. If n = 580 and H₀ predicts 3/4 : 1/4, then E(purple) = 435, E(white) = 145. Expected numbers need not be integers — that is fine, since they represent an average expectation over many hypothetical repeats of the experiment, not a claim about any single count.
Step 3 — Compute the deviation for each class and square it. For each phenotypic or genotypic class, calculate (O − E), the difference between the observed count and the expected count. Square each deviation to remove sign (both overcounts and undercounts represent a deviation from the hypothesis, and squaring prevents positive and negative deviations across classes from canceling).
Step 4 — Scale each squared deviation by its own expected value. Divide (O − E)² by E for that class, not by some overall total. This scaling is essential: a deviation of 10 individuals matters enormously if only 20 are expected, but is trivial if 2,000 are expected. Dividing by E converts an absolute deviation into a relative, sampling-appropriate deviation.
Step 5 — Sum across all classes to get χ².
where k is the number of phenotypic (or genotypic) classes. Larger χ² values indicate greater overall deviation from the hypothesis; χ² = 0 would mean a perfect match between observed and expected counts.
Step 6 — Determine degrees of freedom (df). df = k − 1, where k is the number of classes. One degree of freedom is "used up" because the total sample size n is fixed (once you know the total and all-but-one class counts, the last class count is determined by subtraction — it is not free to vary independently). For a monohybrid 3:1 test, k = 2, so df = 1. For a dihybrid 9:3:3:1 test, k = 4, so df = 3.
Step 7 — Compare χ² to the chi-squared distribution to obtain a p-value. The chi-squared distribution is a family of probability density curves, one for each df, describing how χ² values are distributed under repeated random sampling when H₀ is true. Statistical tables (or software) give the p-value directly: the probability, under H₀, of obtaining a χ² statistic at least as large as the one calculated.
Step 8 — Apply a significance threshold and interpret. By convention, p < 0.05 is treated as statistically significant deviation — the hypothesis is rejected. p ≥ 0.05 means the data do not provide strong grounds to reject H₀; the hypothesis remains a viable explanation, though it is not thereby "proven." A critical value table encodes Step 7 without needing the full distribution function:
| df | p = 0.05 critical χ² | p = 0.01 critical χ² |
|---|---|---|
| 1 | 3.84 | 6.64 |
| 2 | 5.99 | 9.21 |
| 3 | 7.81 | 11.34 |
| 4 | 9.49 | 13.28 |
| 5 | 11.07 | 15.09 |
If the calculated χ² exceeds the tabled critical value at p = 0.05 for the relevant df, the deviation is judged statistically significant and H₀ is rejected.
The second figure shows how the shape of the chi-squared distribution itself changes with degrees of freedom, and why the same raw χ² value can mean very different things depending on how many classes were tested.
The key mechanistic point illustrated here: a χ² of 8.0 would be highly significant evidence against a 3:1 hypothesis (df = 1, critical value 3.84) but would not be significant against a 9:3:3:1 hypothesis with an additional class tested (df = 3, critical value 7.81 — borderline) and would be clearly non-significant against a five-class hypothesis (df = 5, critical value 11.07). Degrees of freedom are not a bookkeeping afterthought; they change the meaning of the number.
The evidence
The chi-squared statistic was introduced by the English mathematician Karl Pearson in a landmark 1900 paper, "On the criterion that a given system of deviations from the probable in the case of a correlated system of variables is such that it can be reasonably supposed to have arisen from random sampling." Pearson was working on problems of goodness-of-fit in general statistics — testing whether observed frequency distributions (of anything from measured skulls to gambling outcomes) matched theoretical ones — and derived the sum-of-squared-standardized-deviations statistic and showed that, for large samples, it followed what became known as the chi-squared distribution. This was a general statistical tool, not originally a genetics-specific one, but it was rapidly adopted by geneticists in the early twentieth century because Mendelian ratios are exactly the sort of quantitative, falsifiable hypothesis the test was built for. The most historically important — and still debated — application of chi-squared reasoning to genetics is not a confirmation but a critique: R.A. Fisher's 1936 statistical re-examination of Gregor Mendel's original pea-breeding data. Mendel, working in the 1850s–60s without any formal significance-testing framework, reported ratios across many crosses (seed shape, seed color, pod shape, flower position, and others) that consistently landed extremely close to their Mendelian predictions — 3:1, 9:3:3:1, and so on. Fisher pooled Mendel's reported results and computed an aggregate chi-squared statistic across all of Mendel's experiments. He found that the overall goodness-of-fit was suspiciously excellent: the combined χ² was so low that the probability of observing data this close to the theoretical ratios, by chance sampling alone, was itself vanishingly small (Fisher calculated the probability of such an unusually good fit occurring by chance at roughly 1 in 10,000 for the aggregated data across experiments). Fisher's famous conclusion was that Mendel's data were "too good to be true" — the deviations from perfect ratios were smaller, on average, than pure chance sampling would be expected to produce. Fisher's critique did not claim fraud outright; several explanations have been proposed since, debated actively among historians and statisticians:
- Unconscious selection bias: Mendel or an assistant may have discarded ambiguous borderline plants (e.g., seeds of intermediate color) when classifying them into discrete categories, unconsciously nudging counts toward the expected ratio.
- Sequential stopping: if Mendel continued counting only until a ratio "looked right" and then stopped, or reported a subset of trials, the reported data would show artificially reduced variance.
- Reporting/publication practices: Mendel may have presented representative, illustrative data rather than every raw count from every trial.
- Fisher's own analysis being flawed: later statisticians (notably Sandler and Sandler in 1950, and others through the late twentieth century) have questioned specific assumptions in Fisher's pooling method, arguing the "too good" result may itself be partly an artifact of how Fisher combined independent experiments, or that some agreement is expected because Mendel likely reported illustrative rather than literal totals for some traits.
What makes this episode pedagogically vital is that it demonstrates the chi-squared test cutting both ways: it is used to flag ratios too far from expectation (evidence against a hypothesis) but Fisher showed it equally flags ratios suspiciously too close to expectation (evidence of some non-random process shaping the data — whether bias, selection, or reporting practice). A statistically literate geneticist checks both tails, not just "did we reject the null." The test's routine, confirmatory use is exemplified by countless twentieth-century linkage and complementation studies: for instance, testcross data used to establish that two genes assort independently are only convincing if the observed 1:1:1:1 ratio survives a chi-squared test with a non-significant p-value; if it does not, the deviation itself becomes evidence of linkage, which is then quantified using recombination frequency — a direct bridge from this test to mapping.
Worked examples
Example 1 — A dihybrid testcross with an asymmetric, non-round sample size. A geneticist crosses a plant heterozygous at two loci controlling seed shape and seed color (RrYy, round/yellow) to a homozygous recessive tester (rryy, wrinkled/green). Under independent assortment, the testcross hypothesis predicts a 1:1:1:1 ratio across four phenotypic classes: round-yellow, round-green, wrinkled-yellow, wrinkled-green. From 618 total offspring, the following are observed:
| Phenotype | Observed (O) | Expected proportion | Expected (E) |
|---|---|---|---|
| Round, yellow | 179 | 1/4 | 154.5 |
| Round, green | 132 | 1/4 | 154.5 |
| Wrinkled, yellow | 141 | 1/4 | 154.5 |
| Wrinkled, green | 166 | 1/4 | 154.5 |
| Total | 618 | 1 | 618 |
Compute (O − E)²/E for each class:
- Round-yellow: (179 − 154.5)² / 154.5 = (24.5)² / 154.5 = 600.25 / 154.5 = 3.885
- Round-green: (132 − 154.5)² / 154.5 = (−22.5)² / 154.5 = 506.25 / 154.5 = 3.277
- Wrinkled-yellow: (141 − 154.5)² / 154.5 = (−13.5)² / 154.5 = 182.25 / 154.5 = 1.180
- Wrinkled-green: (166 − 154.5)² / 154.5 = (11.5)² / 154.5 = 132.25 / 154.5 = 0.856
χ² = 3.885 + 3.277 + 1.180 + 0.856 = 9.20 Degrees of freedom: k = 4 classes, df = 4 − 1 = 3. From the critical value table, at df = 3, the critical χ² at p = 0.05 is 7.81. The calculated χ² (9.20) exceeds this, and in fact exceeds the p = 0.05 threshold but falls short of the p = 0.01 threshold (11.34), placing the p-value roughly between 0.01 and 0.05 (more precisely, p ≈ 0.027).
Interpretation: the deviation from a 1:1:1:1 ratio is statistically significant at the conventional 0.05 threshold. The hypothesis of independent assortment is rejected. The excess of round-yellow and wrinkled-green classes over round-green and wrinkled-yellow (the "parental-like" combinations exceeding the "recombinant-like" ones) is the classic signature of linkage between the seed-shape and seed-color loci — the genes are not assorting independently, and this χ² result is precisely the statistical trigger that tells a geneticist to proceed to calculating recombination frequency rather than accepting simple Mendelian assortment.
Example 2 — A modified dihybrid ratio (epistasis) with small, asymmetric class sizes. In a cross investigating coat color in a rodent species, two genes are hypothesized to interact via recessive epistasis, in which homozygosity at one locus (ee) masks the expression of color alleles at a second locus, producing a modified 9:3:4 ratio instead of the standard 9:3:3:1 (agouti : black : albino/masked). An F₁ dihybrid intercross (EeCc × EeCc) produces 96 offspring:
| Phenotype | Observed (O) | Expected proportion | Expected (E) |
|---|---|---|---|
| Agouti | 58 | 9/16 | 54.0 |
| Black | 15 | 3/16 | 18.0 |
| Albino (masked) | 23 | 4/16 | 24.0 |
| Total | 96 | 1 | 96 |
Compute each term:
- Agouti: (58 − 54)² / 54 = 16 / 54 = 0.296
- Black: (15 − 18)² / 18 = 9 / 18 = 0.500
- Albino: (23 − 24)² / 24 = 1 / 24 = 0.042
χ² = 0.296 + 0.500 + 0.042 = 0.838 Degrees of freedom: k = 3 classes, df = 3 − 1 = 2. Critical χ² at df = 2, p = 0.05, is 5.99. The calculated χ² (0.838) is far below this critical value, corresponding to a p-value well above 0.05 (p ≈ 0.66).
Interpretation: the data are entirely consistent with the hypothesized 9:3:4 recessive epistasis ratio; there is no statistical basis to reject this hypothesis. Note the asymmetry built into this example deliberately: the black class showed the largest relative deviation (15 observed vs. 18 expected, a 17% shortfall) yet contributed only a modest amount to χ² because its expected count was small; the agouti class showed a smaller relative deviation but a larger absolute one. This is exactly why chi-squared scales each squared deviation by its own expected value rather than using raw deviations — it prevents a class with few individuals from being ignored, and prevents a class with many individuals from dominating the statistic purely by size rather than by true departure from expectation.
Common misconceptions & traps
| Misconception | Why it's wrong |
|---|---|
| "A high p-value proves the null hypothesis is true." | A high p-value only means the data are consistent with H₀; it never proves H₀, since other hypotheses (including some untested ones) might fit equally well or better. |
| "A significant χ² (p < 0.05) proves Mendelian genetics is wrong here." | It only rejects the specific null hypothesis tested (e.g., independent assortment); the real cause could be linkage, gene interaction, differential viability, or scoring error — the test does not diagnose why. |
| "Bigger χ² always means a bigger, more important effect." | χ² depends on both effect size and sample size; a trivial deviation in a huge sample can generate a large, "significant" χ², and this is why effect size (e.g., recombination frequency) must be reported alongside p-values. |
| "Degrees of freedom equal the number of genes." | df is determined by the number of phenotypic/genotypic classes in that specific test (k − 1), not by the number of genes involved — a monohybrid test always has df = 1 regardless of how many genes underlie the trait. |
| "You can add up counts from totally different crosses and treat them as one bigger chi-squared test." | Pooling data across heterogeneous experiments without checking homogeneity (a separate chi-squared test for homogeneity) can mask real differences between the datasets — this is part of what made Fisher's reanalysis of Mendel's pooled data statistically delicate. |
| "p < 0.05 is a law of nature." | 0.05 is a conventional, arbitrary threshold; different fields and different stakes (e.g., clinical genetics) may reasonably use stricter cutoffs. |
The scientist behind it
Karl Pearson (1857–1936) was a mathematician, biometrician, and one of the founders of modern mathematical statistics, working at University College London, where he built the discipline of biometry alongside collaborators including Raphael Weldon and, contentiously, Francis Galton's eugenic program (a legacy now widely and rightly criticized). Pearson was obsessed with putting biological variation on a rigorous quantitative footing — asking not just whether two populations seemed different, but by how much, and whether that much could be attributed to chance. His 1900 paper introducing the chi-squared goodness-of-fit statistic was part of this broader biometric program, aimed initially at questions like whether dice were fair or whether measured biological variation matched theoretical distributions, not specifically at Mendelian genetics — indeed, Pearson was for years a skeptic of Mendelism, favoring a more continuous, biometric view of heredity, which set him in a famous scientific rivalry with the Mendelians (including William Bateson). It was the next generation — most importantly R.A. Fisher (1890–1962), who unified Mendelian genetics with biometric variation and refined the theory of statistical significance testing and degrees of freedom — who turned Pearson's tool into the standard workhorse of genetic hypothesis testing used today, while also turning it back, critically, on Mendel's own historical dataset.
Origins · 1 minKarl Pearson and how this was discovered
Where this matters today
Chi-squared goodness-of-fit testing remains a first-line tool anywhere a genetic hypothesis makes a quantitative prediction that can be checked against counted data. In clinical genetics, deviations from expected Mendelian segregation ratios in pedigrees can flag reduced penetrance, genetic linkage to a disease locus, or segregation distortion (non-Mendelian transmission caused by phenomena like meiotic drive or gamete/embryo lethality) — all detectable first as a statistically significant chi-squared deviation before the underlying mechanism is identified. In agricultural and plant breeding programs, chi-squared tests on F₂ or backcross populations confirm whether a trait of interest (disease resistance, seed color, dwarfing) behaves as a single Mendelian locus, two interacting loci, or a polygenic trait, guiding decisions about how many genes must be tracked in a marker-assisted breeding scheme. In genome-wide association and linkage studies, chi-squared and related tests (including its extension in contingency table analysis) test whether allele or genotype frequencies deviate from Hardy-Weinberg equilibrium expectations — a deviation can indicate genotyping error, population stratification, or genuine selection at that locus, making chi-squared testing a standard quality-control step before any downstream association analysis is trusted. In conservation genetics, chi-squared tests on offspring ratios from captive breeding programs of endangered species help detect inbreeding depression or segregation distortion affecting a critical trait (such as a disease-resistance allele), informing breeding pair selection to preserve genetic diversity. In model-organism research (Drosophila, yeast, C. elegans, mice), chi-squared testing of cross progeny remains the everyday first check before any claim of gene linkage, complementation, or novel mutant phenotype segregation is published — precisely the statistical foundation that makes subsequent techniques like Complementation Analysis trustworthy, since complementation tests themselves rely on scoring progeny ratios that must first be shown to depart significantly, or not, from expectations built on Mendelian Inheritance and Independent Assortment.
Ask the tutor: How do I decide whether a significant chi-squared result in a dihybrid cross reflects linkage versus reduced viability of one genotypic class?
Why can't we just compare observed and expected percentages directly instead of using chi-squared?
Percentages alone ignore sample size, and sample size determines how much chance deviation is plausible. A ratio of 78%:22% from a sample of 20 offspring could easily arise from a true 3:1 (75:25) ratio by chance, but the same 78%:22% split from a sample of 2,000 offspring would be a strong signal of real deviation. Chi-squared incorporates sample size explicitly through the expected counts (E), which scale with n, so the same percentage deviation yields a much larger, more decisive χ² statistic as sample size grows. This is precisely why the test, not raw percentages, is the standard for genetic hypothesis testing.
What does it mean if my chi-squared p-value is exactly at the 0.05 boundary?
A p-value near 0.05 sits at a conventional, somewhat arbitrary line, not a sharp scientific cliff between "true" and "false." Statisticians generally recommend reporting the actual p-value rather than just "significant" or "not significant," and treating borderline results (say, 0.03–0.08) as a signal to replicate the experiment with a larger sample rather than making a firm claim either way. In genetics specifically, a borderline result on a linkage or assortment test is often followed up with additional crosses or a larger combined dataset before any conclusion about linkage or gene interaction is drawn.
Can chi-squared goodness-of-fit tell me which gene or mechanism is causing a deviation?
No. The test only tells you whether the data are statistically inconsistent with a specific stated hypothesis; it says nothing about why. A significant deviation from a 9:3:3:1 dihybrid ratio could reflect linkage, differential embryonic or gametic viability among genotypes, gene interaction (epistasis), scoring or classification error, or even chance in a small sample despite the low p-value implying otherwise. Diagnosing the actual cause requires additional experiments — for instance, calculating recombination frequency to test for linkage, or performing reciprocal crosses to rule out maternal or cytoplasmic effects.
Is chi-squared goodness-of-fit the same as a chi-squared test of independence?
No, though they share the same underlying statistic and distribution. Goodness-of-fit compares observed counts in one set of categories to a single theoretical hypothesis (e.g., a 3:1 ratio). A test of independence (using a contingency table) instead asks whether two categorical variables measured on the same individuals are statistically associated — for example, whether phenotype at one locus is independent of phenotype at another locus across a population. The formula (O − E)²/E is computed the same way in both cases, but the source of the expected values, and the degrees-of-freedom formula, differ: contingency tables use df = (rows − 1) × (columns − 1).
How large does a sample need to be for the chi-squared test to be valid?
The chi-squared approximation to the true sampling distribution becomes unreliable when expected counts (E) in any class are very small. A widely used rule of thumb is that no expected class count should fall below 5; when expected counts are smaller than this (common with rare phenotypes or small litters), an exact test such as the binomial test or Fisher's exact test is more appropriate than chi-squared, because the chi-squared distribution is a large-sample approximation, not an exact probability model.
Does failing to reject the null hypothesis mean the cross definitely shows simple Mendelian inheritance?
Not definitively. Failing to reject means the data are statistically compatible with the hypothesized ratio, which is meaningful support, but statistical tests cannot rule out every alternative explanation, especially ones producing very similar predicted ratios or ones simply undetectable at the sample size used. A small sample might fail to reject a 3:1 hypothesis even when the true underlying ratio is subtly different (a modified 3:1 due to weak selection, for instance), because the test lacks the statistical power to detect small deviations at that sample size.
Why did Fisher's finding that Mendel's data fit "too well" become controversial rather than simply accepted?
Because it raises an uncomfortable possibility — bias or selective reporting in a canonical, formative dataset of genetics — without offering a single definitive explanation. Subsequent statisticians have questioned aspects of Fisher's method, including how independent trials were pooled and whether the aggregate probability calculation properly accounted for the number of comparisons Mendel made across many trait types. The consensus today leans toward some combination of unconscious classification bias and selective/illustrative reporting practices common in nineteenth-century science, rather than deliberate fraud, but the episode remains a live case study in how statistical scrutiny of even foundational data must be applied evenhandedly, including to unusually clean results.