Skip to content

How to Use the Hardy-Weinberg Equation

The Hardy-Weinberg equation is one line of algebra — the expansion of (p + q)² — and almost every error made with it comes from using it in the wrong direction. Forward, it turns allele frequencies into the genotype classes a population should show. Backward, it turns a disease rate into the number of healthy carriers nobody has counted. In between sits the use that courses actually examine: treat the squared frequencies as a null hypothesis, compare a typed sample against them, and find out whether the population is behaving as the model assumes. The Hardy-Weinberg calculator does all three directions and prints the intermediate arithmetic, so each step below can be checked rather than taken on trust.

What the equation claims

Write p for the frequency of one allele at a locus and q for the other, so p + q = 1. If mating with respect to that locus is effectively random, the genotype frequencies settle after one generation at:

f(AA) = p²      f(Aa) = 2pq      f(aa) = q²

The 2 in the middle term is not decoration. There are two ordered ways to become a heterozygote — the allele arrives from the mother or from the father — and both routes land in the same class. That single factor explains the most counterintuitive fact in population genetics: at q = 1%, affected people are q² = 0.01% of the population while carriers are 2pq = 1.98%, so roughly 98% of the copies of a rare disease allele are sitting in people who will never have the condition.

The claim is about a population, not a family. A cross between two known parents is Mendelian bookkeeping over four boxes; this is a frequency statement over thousands of strangers. The Punnett square calculator answers the family question, and mixing the two is the most common way these numbers get misquoted.

Step 1 — count alleles, not people

Genotype counts are the raw evidence, and each person contributes two alleles: a homozygote contributes two copies of its allele, a heterozygote one of each.

p̂ = (2·nAA + nAa) / 2N        q̂ = 1 − p̂

For 100 typed people — 60 AA, 30 Aa, 10 aa — the tally is 2·60 + 30 = 150 copies of A and 2·10 + 30 = 50 copies of a out of 200 alleles, giving p̂ = 75% and q̂ = 25%. The denominator is 2N, and it matters twice over: it is what the allele frequency means, and it is the n a confidence interval is computed on later.

Step 2 — square, then multiply by the sample

Take those frequencies back to the classes the population should show, and scale by N to get expected headcounts:

Class Frequency Expected of 100 Observed
AA p² = 0.5625 56.25 60
Aa 2pq = 0.375 37.50 30
aa q² = 0.0625 6.25 10

Observed counts are whole people; expected counts are not, and they should not be rounded before the next step. The gap here is 7.5 missing heterozygotes and 3.75 extra aa individuals.

Step 3 — test the gap with the right degrees of freedom

Pearson’s statistic sums the squared gaps, scaled by what was expected:

χ² = Σ (O − E)² / E          p = P(χ²_df ≥ χ²)

For the table above: 0.25 + 1.50 + 2.25 gives χ² = 4.00, and at one degree of freedom the tail probability is 4.55%.

The degrees of freedom are where most worked solutions go wrong. The rule is classes − 1 − the allele frequencies estimated from the same data, not the plain goodness-of-fit count, because p̂ was taken from the very sample being tested:

Locus Classes Frequencies estimated df
Two alleles (AA, Aa, aa) 3 1 (p; q = 1 − p) 3 − 1 − 1 = 1
Three alleles (six classes) 6 2 (p and q; r = 1 − p − q) 6 − 1 − 2 = 3

That is the shorthand “classes − alleles” — three classes and two alleles leave one degree of freedom — and the 5% critical value at df 1 is 3.84, so χ² = 4.00 sits just past it: a marginal failure rather than a discovery. At df 3 the same 5% line is at 7.81, which is why reporting an oversized locus at df 1 turns a passing test into a failing one on paper.

Step 4 — read the direction, with F

A chi-square has no sign: it grows whether heterozygotes are missing or excess, and it grows with sample size regardless of the biology. The inbreeding coefficient fixes both problems:

F = 1 − Ho / He        Ho = nAa / N        He = 1 − Σpᵢ²

Here Ho = 30% against He = 37.5%, so F = 0.2: 20% of the heterozygotes the frequencies predicted are simply not there. Flip the sample to 30 AA, 60 Aa, 10 aa and F = −0.25, an excess — a different problem with a different list of causes. Positive F points toward relatives mating, two subpopulations typed as one (the Wahlund effect), or alleles that fail to amplify at a PCR site being scored as homozygotes. Negative F points toward heterozygote advantage, or toward having pooled samples scored differently. The test cannot tell you which; the sign only tells you which list to read.

Step 5 — say how wide the number is

An estimate from a finite sample has a width, and for allele frequencies a Wilson score interval behaves better than the naive normal one at the extremes:

(p̂ + z²/2n ± z·√(p̂(1−p̂)/n + z²/4n²)) / (1 + z²/n),   n = 2N alleles, z = 1.96

The 200 alleles of a 100-person sample give q̂ = 25% a 95% interval of 19.51% to 31.43%. Carry that through 2q(1−q) and the carrier frequency is not “37.5%” but somewhere between 31.40% and 43.11%. This is the step that turns a screening leaflet’s “1 in 50 carriers” into a claim you can compare against another study: if the intervals overlap, nobody has shown anything yet.

When the sample is too small to test

The chi-square is an approximation, and it degrades when expected counts get thin — the usual floor is 5 in any class, and at one degree of freedom some texts ask for 10. Fifteen people with 7 AA, 6 Aa and 2 aa expect only 1.67 aa individuals, so χ² = 0.15 (p = 69.85%) is reporting on the approximation rather than the population, and the honest answer is that this sample cannot tell.

Two things rescue small data. The exact test fixes the allele counts and asks how the heterozygote could have been distributed among the three classes:

P(nAa | alleles) ∝ N! / (nAA! · nAa! · naa!) · 2^nAa

summing the arrangements no more likely than the observed one — for the 15-person sample it returns p = 100%, which is a statement, not a shrug. The second is a sample-size floor: at these frequencies 45 people are needed before the rarest expected class reaches 5, and at the 75/25 frequencies of the first example that floor is 80. A page that reports a chi-square without either of those is asking you to trust an approximation it has not checked.

Running it backward from a disease rate

When only the affected fraction is known, invert the squaring rule. For a fully penetrant recessive trait the affected are q², so:

q = √(affected)        carrier = 2pq        carriers among unaffected = 2q / (1 + q)

That last form is the one a counselor quotes, because the person asking is usually unaffected; it is always the larger number, and for rare diseases the two differ only in the fourth decimal.

Affected births Allele frequency q Carriers 2pq Carriers among unaffected One carrier in
1 in 1,000 3.1623% 6.1246% 6.1307% 16.33
1 in 10,000 1% 1.98% 1.9802% 50.51
1 in 25,000 0.6325% 1.2569% 1.2570% 79.56
1 in 1,000,000 0.1% 0.1998% 0.1998% 500.5

A dominant trait inverts differently, and this is the error that costs the most, because the input looks identical. A fully penetrant dominant allele puts the affected in p² + 2pq = 1 − q², so you take the square root of the unaffected fraction:

q = √(1 − affected)        p = 1 − q

With 19% of a population showing the trait, q = √0.81 = 0.9 and the disease allele sits at p = 10%. The classes come out 1% homozygous dominant, 18% heterozygous, 81% unaffected — which is why dominant conditions are so rarely seen in homozygous form. Read that same 19% as recessive and you get q = 43.6%, a frequency four times larger and completely wrong.

X-linked loci need two tables

A male has one X, so his phenotype reports his genotype directly: the male rate is q. A female needs the allele twice to be affected (q²) and once to be a carrier (2pq). At 8% of males affected for a recessive X-linked trait, females show 0.64% affected (1 in 156), 14.72% carriers (1 in 6.8) and 84.64% with neither copy. There is no single p² + 2pq + q² table for such a locus in a mixed population, which is why any result that averages the sexes is describing something that does not exist.

From population carriers to one couple

Chain the two directions carefully and a disease rate becomes a couple-level figure:

C = 2pq                    P(both carriers) = C²
P(affected child) = C² × 1/4

If 2% of people carry one copy, a randomly paired couple are both carriers 0.04% of the time, and the expected affected births are 0.04% × ¼ = 0.01% — one in 10,000. Start from q = 1% instead and carriers come out 1.98%, giving one affected birth in 10,203. Note what is doing the work: random mating. Two carriers who happen to be cousins, or a couple from a group where the frequency differs, sit outside the C² arithmetic entirely, and for a couple already known to be carriers the answer is the Mendelian one-in-four, not a population figure.

Three worked examples

A locus that passes. 100 people at a three-allele codominant marker: 14 AA, 18 AB, 14 AC, 20 BB, 18 BC, 16 CC. Allele frequencies from the 200 alleles are A 30%, B 38%, C 32%; the six classes minus three frequencies leave df = 3; χ² = 12.22 gives p = 0.67%, and observed heterozygosity 50% against an expected 66.32% puts F at 0.246. A real deficit, visible because the degrees of freedom were counted properly.

A sample that cannot answer. 15 people, 7 AA / 6 Aa / 2 aa: p̂ = 66.67%, but the expected aa count is 1.67 and the exact test returns p = 100%. Report the 45-person floor, not the p-value.

A carrier figure for a family. Cystic-fibrosis-style numbers: 1 in 2,500 births affected would be q² = 0.04%, q = 2%, carriers 2pq = 3.92% and 1 in 25.5 among the unaffected. Those are the screening figures commonly quoted — and they are interval estimates from a defined population, which is why a “1 in 25” leaflet and your own family history can both be right.

Common mistakes

  • Putting percentages or ratios into the count fields. The test weighs a deviation by sample size; without N it has no meaning.
  • Reporting χ² at df = classes − 1, which understates the p-value at two alleles and badly understates it at three.
  • Treating a large p-value as proof of equilibrium when the sample was too small to see anything.
  • Applying q = √(affected) to a dominant trait, silently solving the wrong equation.
  • Quoting 2pq as a couple’s risk instead of the share of strangers carrying one copy.
  • Averaging male and female rates at an X-linked locus.
  • Ignoring reduced penetrance: an observed “affected” fraction is only q² if every carrier-with-the-genotype shows the phenotype.

Frequently asked questions

Does a population have to be in Hardy-Weinberg equilibrium? No, and most real ones are not exactly. The squared proportions are a reference point that says whether the deviations are small enough for the simple model to be used, which for many purposes they are.

Why does my sample fail the test at a locus nobody cares about? Because a chi-square grows with N. A deficit of one person in a hundred can be non-significant, and the same deficit in a cohort of a hundred thousand is. Look at F, not only at p.

Can I use this on my own family? Not directly. Family risks start from the parents’ genotypes, which is Punnett-square territory. This equation tells you how common the alleles are, and how much of that rarity is hidden in carriers.

How many alleles can a locus have here? The calculator counts two or three from genotype counts and takes two to four frequencies as input. More than that needs the same multinomial arithmetic and a table nobody publishes.

What if my marker has null alleles? Heterozygotes carrying an undetected allele are scored as homozygotes, which inflates F in the positive direction without any inbreeding at all. That is a genotyping artifact, and the test will happily report it as significant.

Where to go next

Work the same numbers through the interface — counts, expected frequencies, disease rates, X-linked loci and the random-couple chain are five separate modes on the Hardy-Weinberg calculator, and the Genetics collection lists the neighboring tools. If the question on your desk is about two specific people rather than a population, start with how to read a Punnett square instead.

Scientific Sources

External links open in a new tab and carry rel="nofollow". We cite primary references (NIST, NIH/NCBI, peer-reviewed papers) and established manufacturer technical documentation (NEB, Thermo Fisher, Promega, IDT). Calculated results are estimates; your protocol and manufacturer guidance take precedence.