Hardy-Weinberg Calculator: Allele and Genotype Frequencies with a χ² Test
By FindMySum · Last reviewed
The Hardy–Weinberg principle is the baseline of population genetics: in a large population where nothing is changing allele frequencies, genotype frequencies settle at predictable proportions and stay there. This Hardy–Weinberg calculator works out allele frequencies from genotype counts and tests whether those counts fit equilibrium, estimates allele and carrier frequencies from how common a recessive trait is, and extends the principle to three alleles for the ABO blood groups.
The equations
For one gene with two alleles, A at frequency p and a at frequency q:
- p + q = 1
- p² + 2pq + q² = 1
The three terms are the expected frequencies of AA, Aa and aa. They follow from random mating: an individual gets A from each parent with probability p, so AA has probability p², aa has q², and Aa can arise two ways, giving 2pq.
From genotype counts
If you can tell all three genotypes apart, as with codominant blood groups or a DNA marker, count alleles:
- p = (2 × AA + Aa) ÷ 2N
- q = 1 − p
where N is the number of individuals. Multiply p², 2pq and q² by N to get the counts expected at equilibrium, then compare them with the observed counts.
Worked example: the default sample
The calculator opens with 360 AA, 480 Aa and 160 aa individuals, 1,000 in all.
- p = (2 × 360 + 480) ÷ 2,000 = 1,200 ÷ 2,000 = 0.6, and q = 0.4
- Expected AA = 0.6² × 1,000 = 360, expected Aa = 2 × 0.6 × 0.4 × 1,000 = 480, expected aa = 0.4² × 1,000 = 160
The observed and expected counts match exactly, so χ² = 0 and the sample sits in equilibrium. Change the counts to 50, 20 and 30 and p is still 0.6, but now there are far fewer heterozygotes than the 48 expected. χ² climbs to 34, with a p-value around 5 × 10⁻⁹: strong evidence the population is not mating at random, or that something such as inbreeding or population mixing is at work.
The χ² test for equilibrium
The test statistic is χ² = Σ (observed − expected)² ÷ expected over the three genotypes. It has one degree of freedom: three classes, minus one because the counts add to N, minus one more because p was estimated from the same data. A χ² above 3.84 means p < 0.05, the usual threshold for rejecting equilibrium. The table shows each genotype's contribution, so you can see which class drives a departure. When any expected count falls below 5 the approximation weakens, and the page says so.
From a recessive trait
Often only the recessive phenotype can be recognised, because AA and Aa look alike. Then q² is the share of people with the trait, and q = √q². If 1 person in 2,500 has a recessive trait, q² = 0.0004, q = 0.02 and p = 0.98. Carriers are 2pq = 3.92%, about 1 in 25.5. This shows why rare recessive conditions persist: about 98 copies of the allele out of every 100 sit in healthy carriers, where selection cannot act on them. The calculation assumes equilibrium, which cannot be checked from phenotype counts alone.
Three alleles: ABO blood groups
With three alleles the genotype frequencies are the terms of (p + q + r)²: p², q², r², 2pq, 2pr and 2qr. In the ABO system Iᴬ and Iᴮ are codominant with each other and both dominant to i, so:
- Group A = p² + 2pr
- Group B = q² + 2qr
- Group AB = 2pq
- Group O = r²
Enter p and q and the calculator sets r = 1 − p − q. With p = 0.3, q = 0.1 and r = 0.6, it predicts 45% group A, 13% B, 6% AB and 36% O. Working backwards from observed blood-group frequencies, r is √(O), a method first used by Felix Bernstein in 1924 to show that ABO is controlled by one gene with three alleles.
Assumptions and limits
Hardy–Weinberg proportions hold exactly only in an idealised population: very large, randomly mating, with no selection, no mutation, no migration and equal survival of all genotypes. Real populations break these assumptions to some degree, and the χ² test is one way to see how much. The calculator handles one autosomal gene at a time. It does not cover sex-linked genes, more than three alleles or linkage between genes, and it describes populations, not the genetic risk of any individual, which needs family history, testing and genetic counselling.
More questions
Who were Hardy and Weinberg?
G. H. Hardy was an English mathematician who published the principle in Science in 1908, partly to answer the mistaken idea that dominant alleles must spread until three quarters of a population show them. Wilhelm Weinberg, a German physician, derived the same result independently the same year. The principle is sometimes called the Hardy–Weinberg–Castle law after William Castle's 1903 work.
Does a dominant allele become more common over time?
Not on its own. Dominance only decides which phenotype a heterozygote shows; it does nothing to the allele frequencies. Without selection, mutation, migration or drift, a rare dominant allele stays rare and a common recessive one stays common. This was the point Hardy's paper made.
What is the difference between allele frequency and genotype frequency?
An allele frequency is the share of all copies of a gene in the population that are one version (p for A). A genotype frequency is the share of individuals with a particular pair (AA, Aa or aa). Each person carries two copies, so a population of 1,000 has 2,000 copies to count for the allele frequencies.
How many generations does it take to reach equilibrium?
For one autosomal gene, just one generation of random mating. Whatever the starting genotype mix, the offspring of a randomly mating population have p², 2pq and q² proportions. Genes on the X chromosome take several generations to converge because males and females carry different numbers of copies.
What sample size do I need for the χ² test?
The χ² approximation is reliable when every expected count is at least about 5. For rare alleles or small samples the expected number of homozygotes for the rare allele is often below that, and population geneticists use an exact test instead (Wigginton, Cutler and Abecasis, 2005). The calculator warns when an expected count is under 5.
Why do geneticists use Hardy–Weinberg tests on DNA data?
As a quality check. In large genotyping studies, a marker that departs strongly from equilibrium in healthy controls often points to a genotyping error, such as one allele failing to amplify, rather than to real biology. Markers that fail the test are commonly removed before analysis.
Sources
This article explains how the calculator works and is general information, not financial, tax, legal or medical advice. Rules change; check the sources above or a qualified professional before you act.