Testing Hardy-Weinberg Equilibrium
Why do MN blood-group genotypes in almost every human population match a simple algebraic prediction? Sickle-cell genotypes in malaria-endemic regions never do. The answer separates loci that behave as inert bookkeeping problems from loci actively shaped by selection, mating patterns, or population structure. The Hardy-Weinberg Principle gives a null expectation for genotype frequencies from allele frequencies alone. But a principle is only useful once you can ask, rigorously, whether real data obey it or violate it — and by how much. This article is about that test. Geneticists routinely count genotypes in a sample — AA, Aa, aa individuals, or the analogous classes at a marker locus. They need to know whether observed counts differ from the Hardy-Weinberg (HW) expectation. The difference must exceed what chance sampling would explain. The tool for this is the chi-square (χ²) goodness-of-fit test. This is the same logical machine used throughout genetics to compare observed and expected ratios. It applies from Mendelian dihybrid crosses to genome-wide association study quality control. The stakes are not merely statistical housekeeping. A locus that fails a Hardy-Weinberg test is flagging something biologically real. Possible causes include nonrandom mating (inbreeding or assortative mating), or population substructure. Population substructure means a hidden mixture of subpopulations, called the Wahlund effect. Other causes include selection against or for a genotype, genotyping error, or a small sample buffeted by chance. Modern genomics runs Hardy-Weinberg tests on millions of SNPs as a first-pass quality filter. A locus wildly out of HW proportions in a supposedly random-mating human cohort often signals a bad genotyping assay. It less often signals a biological miracle. Telling the two apart is where the real skill lies. By the end of this article you will be able to do several things. You will state the null and alternative hypotheses of an HW test precisely. You will compute expected genotype counts from observed allele frequencies. You will carry out and correctly interpret a chi-square test with the right degrees of freedom. You will recognize when a locus's departure reflects biology rather than noise or artifact. And you will see how this single test opens the door to the next question — what forces actually change allele frequencies over time.
- Hardy-Weinberg equilibrium (HWE) predicts genotype frequencies (p², 2pq, q²) from allele frequencies (p, q) under random mating, no selection, no migration, no mutation, infinite population size.
- A chi-square goodness-of-fit test compares observed genotype counts to those expected under HWE to see if any deviation exceeds what sampling error alone predicts.
- Degrees of freedom for a two-allele, three-genotype HW test is 1, not 2, because allele frequencies are estimated from the same data (one extra parameter is "used up").
- Significant departures point to real causes: inbreeding/assortative mating, population stratification (Wahlund effect), selection, or genotyping error — not to any failure of Mendelian inheritance itself.
- A single generation of random mating restores Hardy-Weinberg proportions even after a population starts out badly skewed, as long as no other force is acting — a key theoretical result underlying the whole test.
- Failing to reject the null does not prove equilibrium; it means the sample gave no evidence against it, and sample size strongly affects the power to detect real deviations.
The Hardy-Weinberg chi-square test asks whether observed genotype counts differ from p²:2pq:q² more than random sampling can explain — and a "yes" answer is a discovery, not an error.
The core idea
The Hardy-Weinberg Principle states that in a population mating at random, with no selection, mutation, migration, or genetic drift, allele frequencies remain constant generation after generation, and genotype frequencies settle into a fixed relationship with allele frequencies: if the frequency of allele A is p and of allele a is q (with p + q = 1), then the genotype frequencies are p² (AA), 2pq (Aa), and q² (aa). This is an equilibrium in the strict sense — a population already at these proportions stays there, and a population not at these proportions reaches them after just one generation of random mating (for an autosomal locus with non-overlapping generations). Testing Hardy-Weinberg equilibrium means asking a very specific empirical question: given the allele frequencies estimated from a sample, do the observed genotype counts match the p²:2pq:q² prediction closely enough to be attributable to chance sampling alone? This is a goodness-of-fit problem, structurally identical to testing whether a dihybrid cross gives a 9:3:3:1 ratio. The tool is the chi-square statistic:
summed over genotype classes, where Oᵢ is the observed count and Eᵢ is the count expected under HWE. This statistic is then compared against the chi-square distribution with the appropriate degrees of freedom to obtain a p-value — the probability of seeing a deviation this large (or larger) purely by chance if HWE truly holds. The subtlety that trips up almost every student is the degrees of freedom. With three genotype classes there appear to be 3 − 1 = 2 degrees of freedom, as in any three-category goodness-of-fit test. But the expected values here are not fixed in advance (unlike a 1:2:1 Mendelian ratio) — they are calculated from the allele frequency p, which is itself estimated from the very same sample. Estimating one parameter from the data removes one additional degree of freedom, leaving 1 degree of freedom for a simple biallelic autosomal locus. This single fact — df = (number of genotype classes) − 1 − (number of allele frequencies estimated) — generalizes to multi-allelic systems and is the most commonly misapplied detail in the whole procedure.
Mechanism
Step 1: Count genotypes and estimate allele frequencies. Sample N individuals from the population and classify each at the locus of interest. For a two-allele autosomal locus with alleles A and a, tally the observed counts of AA, Aa, and aa, call them n₁₁, n₁₂, n₂₂, with n₁₁ + n₁₂ + n₂₂ = N. Allele frequencies are then estimated by direct gene counting:
This uses every allele copy in the sample — each homozygote contributes two copies of its allele, each heterozygote contributes one of each.
Step 2: Compute expected genotype counts under HWE. Multiply the HW proportions by the sample size:
Crucially these expected counts are computed from the sample's own allele frequencies, not from some external or historical value — this is what testing HWE actually means: not "does this population match some prior expectation," but "are its genotypes distributed the way its own alleles would predict under random mating."
Step 3: Compute the chi-square statistic and evaluate significance. Apply the formula above across the three classes, then compare to the chi-square distribution with 1 degree of freedom. A conventional threshold is α = 0.05, corresponding to a critical value of χ² = 3.84 for 1 df. If the computed χ² exceeds 3.84, the null hypothesis of HWE is rejected at the 5% level — the genotype distribution departs from Hardy-Weinberg expectation more than chance sampling alone would produce. A small-sample correction (Yates' continuity correction) or, better, an exact test (based on the hypergeometric-like distribution of genotype counts conditional on allele counts, as formalized by Wigginton, Cannings, and others) is preferred when expected counts in any cell fall below about 5, since the chi-square approximation becomes unreliable for sparse data.
Step 4: Interpret the direction of any deviation. Chi-square is symmetric — it flags deviation but not direction. In practice, HW departures typically show one of two recognizable signatures:
- Heterozygote deficit (fewer Aa than expected): the classic signature of inbreeding, assortative mating by genotype, a Wahlund effect from pooling two differentiated subpopulations, or a genotyping artifact that misclassifies heterozygotes as homozygotes (allele dropout in PCR-based assays).
- Heterozygote excess (more Aa than expected): the classic signature of disruptive/balancing selection favoring heterozygotes (as in the sickle-cell/malaria system), negative assortative mating, or certain forms of overdominant selection.
A useful summary statistic tied to this test is the inbreeding coefficient, F, defined operationally as:
where H_obs is the observed heterozygote frequency and H_exp = 2pq. Positive F indicates heterozygote deficit; negative F indicates heterozygote excess; F near zero indicates consistency with random mating. The HW chi-square test is, in effect, asking whether F differs significantly from zero.
The evidence
The single most cited empirical case for treating Hardy-Weinberg departure as biologically meaningful — rather than a statistical curiosity — is the sickle-cell hemoglobin polymorphism in malaria-endemic West and Central Africa, established chiefly through the work of Anthony C. Allison in the 1950s. Allison sampled populations in East Africa (notably the Baamba and other groups near malaria-endemic regions of Uganda and Tanzania) and genotyped individuals at the β-globin locus for the sickle allele (HbS) versus the normal allele (HbA), using electrophoresis and clinical/hematological criteria to distinguish AA, AS, and SS individuals. If the HbS allele were neutral, genotype frequencies among adults should match Hardy-Weinberg proportions computed from the allele frequency in that sample, and there would be no excess of heterozygotes relative to p² : 2pq : q² expectation. What Allison found instead was a substantial and statistically significant excess of AS heterozygotes compared to the Hardy-Weinberg expectation, alongside a corresponding deficit of SS homozygotes among adults relative to newborns — SS individuals suffer very high childhood mortality from sickle-cell disease in the absence of modern medical care, while AS heterozygotes are markedly protected against death from Plasmodium falciparum malaria without suffering serious sickling disease themselves. Chi-square tests on his genotype-count data rejected the HW null hypothesis: the deviation was too large, and too consistently in the heterozygote-excess direction across independent samples and independent malaria-endemic regions, to be attributed to sampling error. Subsequent decades of work — including geographic correlation of HbS allele frequency with historical malaria endemicity across Africa, and direct clinical studies showing lower parasite densities and less severe malaria in AS individuals — confirmed that this rejection of HWE reflected genuine balancing selection favoring the heterozygote (heterozygote advantage/overdominance), not an artifact. This example is historically important for a second reason: it demonstrates that a locus can fail an HW test for a scientifically interesting reason even while satisfying all the other assumptions of the model reasonably well (the populations studied mate close to randomly with respect to sickle-cell genotype, since the trait was unknown to the individuals themselves before modern genetic testing). The departure is not due to inbreeding or population structure — it is due to differential survival, that is, natural selection acting each generation on genotype-specific fitness. This is precisely the diagnostic logic the chi-square HW test is built to expose: reject the null, then use independent biological evidence (fitness measurements, parasite-load data, mortality statistics) to identify which violated assumption is responsible. A complementary, methodologically instructive case comes from human genome-wide association studies (GWAS), where HW testing is now a universal quality-control step rather than a discovery tool. Genotyping platforms occasionally misread heterozygotes as one homozygote class because of technical artifacts (poor probe hybridization, copy-number variation near the SNP, or plate effects), producing spurious heterozygote deficits at specific SNPs. Large consortium studies (e.g., the HapMap Project and subsequent GWAS quality-control pipelines) routinely apply exact HW tests within a homogeneous ancestry group and flag or remove SNPs with p < 10⁻⁶, on the logic that a true, evolutionarily neutral, randomly mating human population should show negligible HW departure at most loci — so a strong departure is far more likely to be a genotyping artifact than a real signal of selection at that specific marker. This large-scale, routine application confirms the logic Allison pioneered on a handful of villages: HW testing turns a purely algebraic prediction into a diagnostic instrument for real biological (or technical) processes.
Worked examples
Example 1 — MN blood group in a sample of 1,000 people. The MN blood group locus has two co-dominant alleles, M and N, giving three directly distinguishable phenotypes/genotypes: MM, MN, NN. Suppose a sample of 1,000 individuals gives:
| Genotype | Observed |
|---|---|
| MM | 298 |
| MN | 489 |
| NN | 213 |
Step 1 — allele frequencies by gene counting:
Step 2 — expected counts under HWE:
Step 3 — chi-square:
Step 4 — with df = 1, the critical value at α = 0.05 is 3.84. Here χ² = 0.222 ≪ 3.84, so we fail to reject HWE: this sample's genotype counts are entirely consistent with random mating at this locus, exactly as expected — MN blood group shows no known selective effect and is a textbook example of a genuinely neutral, HW-conforming polymorphism in humans.
Example 2 — a cattle herd screened for a recessive metabolic disease allele, with an unusual twist. A veterinary geneticist screens 500 cattle in a closed herd for a recessive allele r causing a metabolic disorder, using a DNA test that unambiguously distinguishes RR, Rr, and rr. Results:
| Genotype | Observed |
|---|---|
| RR | 320 |
| Rr | 100 |
| rr | 80 |
This is a smaller heterozygote class than intuition might expect. Allele frequencies:
Expected counts:
Chi-square:
With df = 1, χ² = 115.3 is astronomically above 3.84 (p ≪ 0.0001) — a massive, unambiguous rejection of HWE. The pattern (both homozygote classes over-represented, heterozygotes strongly under-represented) is the classic heterozygote-deficit signature. Given that this is a closed herd, the most parsimonious biological explanation is inbreeding — cattle breeders commonly line-breed from a small number of prized sires, raising the coefficient of relatedness among mates above the random-mating baseline and systematically converting heterozygotes into homozygotes across the whole genome, not just at this locus. Estimating F directly:
An inbreeding coefficient near 0.48 is very high (a full-sib mating produces F = 0.25 in one generation), consistent with sustained close breeding — exactly the kind of finding a herd manager needs in order to diversify sire selection and control the segregation of the recessive metabolic disease allele.
Common misconceptions & traps
| Misconception | Why it's wrong |
|---|---|
| "Rejecting HWE means Mendelian inheritance is violated." | HWE is about population-level mating and selection structure, not about how alleles segregate within an individual's meiosis; a locus can be perfectly Mendelian and still show non-HW genotype frequencies at the population level. |
| "The degrees of freedom for a 3-genotype HW test is 2, just like any 3-category chi-square." | It is 1, because the expected frequencies are computed from an allele frequency estimated from the same sample, consuming one additional degree of freedom. |
| "Failing to reject HWE proves the population is in equilibrium." | Absence of evidence is not evidence of absence; small samples have low power, so a non-significant result may simply reflect insufficient data to detect a real deviation. |
| "A significant chi-square always means selection is acting." | Population stratification (Wahlund effect), inbreeding, assortative mating, and genotyping error can all produce significant departures without any selection at all. |
| "You test HWE by comparing to some fixed 'ideal' allele frequency (like 0.5:0.5)." | The test always uses the sample's own estimated allele frequency to generate the expectation — HWE is a statement about the relationship between allele and genotype frequencies, not about what the allele frequency itself should be. |
| "Any departure, however small, is biologically important." | With very large samples (as in modern GWAS with tens of thousands of individuals), trivially small deviations become statistically significant; effect size (e.g., the inbreeding coefficient F) matters alongside the p-value. |
The scientist behind it
Anthony C. Allison (1925–2014) trained in medicine and biochemistry and pursued fieldwork in East Africa in the early 1950s, where he combined careful population genetic sampling with clinical and physiological experimentation — including exposing his own blood samples containing sickle trait to controlled malaria infection in vitro to test protective mechanisms directly. His genius was methodological: rather than treating the sickle-cell allele's persistence as a curiosity, he applied the quantitative logic of Hardy-Weinberg testing to real population samples, showed that the departure (heterozygote excess) was statistically robust across independent villages, and then closed the loop with direct physiological evidence for why AS heterozygotes resist malaria better than AA homozygotes. This combined statistical-plus-mechanistic approach became the template for how population geneticists validate a suspected case of balancing selection to this day, and it directly foreshadows how modern researchers investigate the many other forces — Genetic Drift, migration, mutation, and various modes of selection — that are collectively responsible for real-world departures from the Hardy-Weinberg null.
Origins · 1 minAnthony C. Allison and how this was discovered
Where this matters today
Genomic quality control. Every modern SNP array or sequencing-based GWAS pipeline runs a Hardy-Weinberg exact test on every marker within each ancestry-matched subgroup. SNPs showing extreme departure (commonly p < 10⁻⁶) are flagged as likely genotyping artifacts and removed before association testing, because a spuriously significant "disease association" is often really just a badly clustered genotyping assay masquerading as heterozygote deficit.
Conservation genetics. Wildlife managers test endangered populations (cheetahs, Florida panthers, island bird populations) for HW departures as an early warning of inbreeding depression, since small, isolated populations lose heterozygosity and drift toward homozygosity — a signal that can inform captive breeding or corridor-building decisions before fitness consequences become visible in the phenotype.
Forensic and paternity genetics. DNA profiling databases used in forensic identification rely on the assumption of HWE (and linkage equilibrium between loci) to calculate match probabilities; forensic laboratories periodically test reference population databases for HW conformity to validate that their statistical match-probability calculations are not systematically biased.
Livestock and plant breeding. Breeders screening herds or crop lines for recessive deleterious alleles (as in the cattle example above) use HW departure and the associated inbreeding coefficient F to detect unwanted inbreeding from restricted sire or seed-parent use, guiding decisions to widen the genetic base of a breeding program.
Human disease genetics and balancing selection. Beyond sickle-cell/malaria, HW-departure analysis remains a live discovery tool for other suspected heterozygote-advantage systems (such as certain HLA loci implicated in pathogen resistance), and continues to be the entry point into the broader study of Genetic Drift, migration, and selection collectively known as the forces that change allele frequencies across generations.
Ask the tutor: How would the chi-square test and degrees of freedom change if I were testing Hardy-Weinberg equilibrium at a three-allele locus like ABO blood type?
Why is the degrees of freedom for the HW chi-square test 1 rather than 2?
With three genotype categories, a standard goodness-of-fit test would use 3 − 1 = 2 degrees of freedom. But the expected genotype counts here are not fixed by theory alone (unlike a 9:3:3:1 Mendelian ratio); they depend on an allele frequency, p̂, that is estimated directly from the same sample being tested. Each parameter estimated from the data removes one additional degree of freedom from the test, so 2 − 1 = 1 degree of freedom remains. This generalizes: with k alleles giving k(*k+1)/2 genotype classes, df = k*(k+1)/2 − 1 − (k−1), since k−1 independent allele frequencies must be estimated.
Does rejecting Hardy-Weinberg equilibrium always mean natural selection is occurring?
No. A significant chi-square only tells you the genotype counts deviate from p²:2pq:q² more than sampling error explains; it does not identify the cause. Non-random mating (inbreeding, assortative mating), population stratification where two genetically distinct subgroups are pooled (the Wahlund effect), genotyping error, and small-sample chance fluctuations can all produce significant departures with no selection whatsoever. Selection (as in the sickle-cell/malaria case) is one possible cause among several, and distinguishing it from the others requires independent evidence — fitness data, pedigree information, or population structure analysis — beyond the chi-square result itself.
Can a locus be in Hardy-Weinberg equilibrium even while allele frequencies are changing over time?
Not in the strict theoretical sense used to derive p²:2pq:q², since that derivation assumes allele frequencies are constant, but in practice a single generation's genotype counts can closely match the current allele frequency's HW prediction even while the underlying allele frequency is drifting or being pushed by weak selection across generations. This is because genotype frequencies re-equilibrate to whatever the current allele frequency is after just one round of random mating; a slowly changing allele frequency produces a slowly moving equilibrium point, and a snapshot chi-square test at any one generation may show no significant departure even though the population is not evolutionarily static.
How does the Wahlund effect cause an apparent Hardy-Weinberg violation without any selection?
The Wahlund effect occurs when a researcher unknowingly samples from two or more genetically distinct subpopulations as if they were one randomly mating population. Each subpopulation individually may be in perfect HWE, but pooling them mathematically reduces the overall observed heterozygosity below what the combined allele frequency would predict, because the variance in allele frequency between subgroups subtracts from expected heterozygosity. The result is a heterozygote deficit and a significant chi-square, purely as a sampling artifact of hidden population structure — a major reason human GWAS studies stratify by ancestry before running HW tests.
What sample size is needed to reliably detect a moderate Hardy-Weinberg departure?
It depends on the allele frequency and the size of the true deviation, but as a rule of thumb, detecting a moderate inbreeding coefficient (F around 0.1–0.2) with reasonable statistical power (80%) typically requires several hundred individuals, while detecting subtle departures (F below 0.05) can require thousands. Rare alleles are especially problematic: if the minor allele frequency is very low, homozygotes for that allele are rare in any reasonably sized sample, expected cell counts fall below the chi-square approximation's reliable range (conventionally below 5), and an exact test should be used instead of the standard chi-square.
Is the Hardy-Weinberg chi-square test valid for loci with more than two alleles, like human HLA genes or ABO blood groups?
Yes, with appropriate adjustment. For k alleles there are k(*k+1)/2 possible genotype classes (homozygotes plus all heterozygote combinations), and expected counts are computed from k*−1 independently estimated allele frequencies (the last is determined by the constraint that frequencies sum to 1). Degrees of freedom become k(*k+1)/2 − 1 − (k*−1). Multi-allele systems like ABO blood groups or HLA loci are tested this way, though with many rare alleles the number of low-count cells often forces the use of exact or permutation-based tests rather than the standard chi-square approximation.
Why does modern genomics treat HW testing mainly as a quality-control step rather than a tool for discovering selection?
In a large, genuinely randomly mating human cohort, the vast majority of neutral SNPs should show negligible departure from HW proportions, so an extreme, highly significant departure at one specific SNP is statistically far more likely to reflect a technical genotyping problem (probe cross-hybridization, copy-number variants near the site, batch effects) than genuine strong selection acting on that single marker. Because true balancing selection strong enough to produce a detectable HW signal is comparatively rare in the genome, geneticists use HW testing defensively — as a filter to catch bad data — while reserving claims of genuine selection for cases supported by independent, converging lines of evidence, exactly as Allison did originally for sickle-cell.