Hardy–Weinberg calculator
Enter what you know: q², p, the share affected or genotype counts. The working is shown, then a chi-square test.
How the calculator works
The Hardy–Weinberg equation links the two allele frequencies, p for A and q for a, to the three genotype frequencies: AA at p², Aa at 2pq and aa at q², with p + q = 1[1][2]. Whatever you enter, the calculator first finds q, then fills in the rest, and the working above shows each step with your own numbers.
- A recessive trait (given as 1 in X, a percentage or q²): only aa individuals show it, so their share is q². Then q = √q² and p = 1 − q.
- A dominant trait (the percentage who show it): AA and Aa look alike, so the share who do not show it is q². Setting p² equal to the share who show it is the commonest mistake; the calculator avoids it.
- p or q: the other is 1 minus it.
- Genotype counts: count gene copies. p = (2 × AA + Aa) / 2n, because each AA individual carries two copies of A and each Aa carries one. This step needs no Hardy–Weinberg assumption.
Expected numbers are the frequencies times the number of people you enter. Frequencies are shown to four decimal places and expected numbers to one decimal place below 100 (whole numbers above), so a column may not add up to its total exactly after rounding.
Two worked examples
A rare recessive condition. A recessive condition affects 1 in 2,500 births. Then q² = 0.0004, q = 0.02 and p = 0.98. Carriers: 2pq = 2 × 0.98 × 0.02 = 0.0392, about 1 in 26. In a town of 10,000 people that is about 392 carriers and 4 affected: carriers outnumber affected people by nearly 100 to 1. Enter “1 in X” with X = 2,500 to see it.
A dominant trait. 84 % of a population show a trait controlled by a dominant allele. The 16 % who do not are aa, so q² = 0.16, q = 0.4 and p = 0.6. Then p² = 0.36 are AA and 2pq = 0.48 are carriers, which together make the 84 %.
Testing a sample: chi-square and the exact test
With genotype counts you can ask whether a sample is in Hardy–Weinberg proportions at all. The test compares observed counts with p²n, 2pqn and q²n and adds up (observed − expected)² / expected over the three classes. With one degree of freedom (three classes, minus one for the total, minus one for the estimated p), a value above 3.84 happens less than 5 % of the time by sampling alone. For small samples or rare alleles, trust the exact test[3], which the calculator reports beside χ². A failed test means at least one assumption below is broken, not which one.
Assumptions and valid range
The frequency results assume Hardy–Weinberg proportions: random mating, no selection on these genotypes, no migration or mutation large enough to matter in one generation, and a population large enough that chance does not distort the genotype shares. Inbreeding (too few heterozygotes), a sample that pools two populations (the Wahlund effect, also too few heterozygotes), or strong selection all break it. For a rare recessive disease the estimate of carriers is usually good; for a trait with incomplete penetrance or several genes, the q² shortcut does not apply. Inputs must be frequencies from 0 to 1, percentages from 0 to 100, or whole-number counts; anything else gets a message instead of a result.
Sources
- (1908). Mendelian proportions in a mixed population. Science 28(706): 49–50. doi:10.1126/science.28.706.49. primary
- (2020). Population and Quantitative Genetics (open textbook, version of October 2021). University of California, Davis (CC BY 3.0). textbook Ch. 2 (Hardy–Weinberg, F), ch. 4 (drift, heterozygosity, fixation), ch. 5 (population structure, island model), ch. 10–12 (selection, selection and drift).
- (2005). A note on exact tests of Hardy–Weinberg equilibrium. American Journal of Human Genetics 76(5): 887–893. doi:10.1086/429864. primary