HARDY-WEINBERG CALCULATOR

Hardy-Weinberg calculator

Allele frequencies, genotype frequencies and carriers from p² + 2pq + q² = 1, plus a chi-square test for equilibrium.

What does the Hardy–Weinberg equation say?

For a gene with two alleles, A with frequency p and a with frequency q, the alleles add up to one: p + q = 1. If mating is random, the genotypes in the next generation appear in the proportions p² (AA), 2pq (Aa) and q² (aa), and these also add up to one (OpenStax Biology 2e, section 19.1). The proportions stay the same from generation to generation as long as nothing pushes the allele frequencies. The idea was published independently in 1908 by G. H. Hardy and Wilhelm Weinberg. It is a null model: when real genotype counts differ from it, something (selection, non-random mating, migration, mutation, drift or sampling) is acting.

How do I get allele and carrier frequencies from the recessive phenotype?

Only the recessive phenotype can be counted directly, because it shows only in aa. Take the square root of its frequency to get q, then p = 1 − q, and the carriers (Aa) are 2pq. As a made-up illustration, if a recessive trait appears in 1 of every 2,500 people, q² = 0.0004, so q = 0.0200 and p = 0.9800. Carriers are 2pq = 0.0392, about 1 in 25.5 people, far more common than the trait itself. This is why a rare recessive condition can sit unseen in many families. The step relies on the equilibrium assumptions, so treat the answer as an estimate, not a screening result.

Worked example: OpenStax pea plants

OpenStax Biology 2e (section 19.1) describes 500 pea plants: 245 YY, 210 Yy and 45 yy. Counting alleles gives 2 × 245 + 210 = 700 Y alleles out of 1,000, so p = 0.7 and q = 0.3. The expected genotypes are 500 × p² = 245, 500 × 2pq = 210 and 500 × q² = 45, identical to what was counted, so χ² = 0 and the population is exactly in equilibrium. In the same section, a population of 500 with q = 0.2 has 320 VV, 160 Vv and 20 vv plants, so 480 show violet flowers and 20 are white.

How does the chi-square test for equilibrium work?

From the genotype counts we estimate p, compute the expected counts N·p², N·2pq and N·q², and add (observed − expected)² ÷ expected over the three classes. There are three classes, we used one parameter (p) estimated from the data, and the counts must add up to N, so the test has 1 degree of freedom, not 2. Example: 40 AA, 40 Aa and 20 aa give p = 0.60, expected counts 36, 48, 16 and χ² = 2.7778. The 5% critical value for 1 degree of freedom is 3.841, so this population is not rejected (p-value 0.0956). A sample of 50 AA, 20 Aa and 30 aa has too few heterozygotes: χ² = 34.0278, p-value 0.00000, so equilibrium is rejected.

When is the chi-square test unreliable?

The χ² statistic is an approximation that needs reasonably large expected counts; the calculator warns you when any expected count is below 5. Wigginton, Cutler and Abecasis (American Journal of Human Genetics 76:887–893, 2005) reported that the standard χ² test can have inflated type I error for rare alleles even in samples of around a thousand people, and proposed exact tests that stay accurate in small samples. If you test many genetic markers, the exact test is the safer choice. The test also says nothing about why a population is out of equilibrium, and a population can pass it while still evolving.

What assumptions does the model make?

OpenStax lists the conditions for Hardy–Weinberg equilibrium: the population is infinitely large, there are no mutations, no migration into or out of the population, and no selection favoring any genotype. Random mating is also assumed for the genotype proportions. No real population meets all of these exactly, so the equation works as a baseline against which change is measured. For humans it is used for population genetics and genetic counseling estimates, but strong inbreeding, assortative mating or a small isolated group can break it badly.

Common mistakes

Mixing up q and q² is the classic error: the frequency of the recessive phenotype is q², and you must take its square root before computing carriers. Another is using 2 degrees of freedom in the χ² test; with p estimated from the data it is 1. Counting heterozygotes as dominant phenotype is fine for phenotype frequencies (p² + 2pq) but not for allele counting from phenotypes alone, where only the recessive class is unambiguous. Finally, the formulas are for two alleles; a locus with three alleles, such as the ABO blood group, needs p + q + r = 1 and (p + q + r)² and is not covered here.

For study and general information only — not genetic counseling or medical advice. Talk with a genetic counselor about your own family. How we check our calculators.

Sources: OpenStax, Biology 2e, section 19.1 “Population Evolution” (Hardy–Weinberg equations, assumptions, pea-plant and violet-flower examples); G. H. Hardy, “Mendelian proportions in a mixed population,” Science 28 (1908): 49–50, and W. Weinberg (1908), the original statements (not opened here); J. E. Wigginton, D. J. Cutler and G. R. Abecasis, “A note on exact tests of Hardy-Weinberg equilibrium,” American Journal of Human Genetics 76 (2005): 887–893. Related: Punnett square calculator, chi-square calculator, hypergeometric calculator, Bayes’ theorem calculator and doubling time calculator.