Understanding the Hardy-Weinberg equilibrium calculator — concept and principle
The Hardy-Weinberg principle predicts genotype frequencies in a population from its allele frequencies, assuming no evolutionary forces are acting. This calculator takes observed counts of the three genotypes AA, Aa and aa at one locus with two alleles, estimates the allele frequencies p and q, calculates the expected counts, and runs a chi-square goodness-of-fit test.
How it is calculated
- Total: N = AA + Aa + aa.
- Allele frequency: p = (2·AA + Aa) ÷ 2N, and q = 1 − p.
- Expected counts: AA = p²N, Aa = 2pqN, aa = q²N.
- Chi-square: χ² = Σ (observed − expected)² ÷ expected over the three classes.
- p-value: from the χ² distribution with 1 degree of freedom (3 classes − 1 − 1 estimated parameter p).
The principle
In a large, randomly mating population with no mutation, migration or selection, gametes combine like independent random draws. The chance of drawing A twice is p × p = p², of drawing a twice is q², and of drawing one of each is 2pq because it can happen in two orders. Since p + q = 1, the three frequencies add up to (p + q)² = 1. After one generation of random mating these proportions stay constant, which is the "equilibrium".
Worked example
- Counts: AA = 360, Aa = 480, aa = 160, so N = 1,000.
- p = (2 × 360 + 480) ÷ 2,000 = 1,200 ÷ 2,000 = 0.6; q = 0.4.
- Expected AA = 0.6² × 1,000 = 360; Aa = 2 × 0.6 × 0.4 × 1,000 = 480; aa = 0.4² × 1,000 = 160, giving 360, 480, 160.
- Every observed count equals its expected count, so χ² = 0.
- p-value = 1: the data fit Hardy-Weinberg proportions perfectly.
| Count AA | p (A) |
|---|---|
| 90 | 0.4520547945 |
| 180 | 0.512195122 |
| 270 | 0.5604395604 |
| 360 | 0.6 |
| 450 | 0.6330275229 |
| 540 | 0.6610169492 |
| 720 | 0.7058823529 |
How to read the result
With 1 degree of freedom, χ² above 3.84 corresponds to p < 0.05, and above 6.63 to p < 0.01. A small p-value means the genotype counts depart from expectation. An excess of homozygotes (fewer Aa than 2pqN) can point to inbreeding, population substructure or genotyping errors such as allele dropout; an excess of heterozygotes can point to selection or sample mixing. A large p-value does not prove equilibrium; it only means no departure was detected.
Common mistakes
- Calculating p as AA ÷ N, which ignores the A alleles in heterozygotes.
- Using 2 degrees of freedom; one is lost because p is estimated from the data.
- Trusting the χ² test when an expected count is below about 5; use an exact test instead.
Frequently asked questions
How do I get carrier frequency from disease incidence?
For a recessive condition, q ≈ √(incidence) and carrier frequency 2pq ≈ 2q when q is small.
Does Hardy-Weinberg mean allele frequencies never change?
It describes the null case without evolutionary forces. Real populations change; the test detects departures.
Why do GWAS pipelines filter SNPs on this test?
Strong departures in controls often signal genotyping errors, so those markers are removed.
Sources: G. H. Hardy, "Mendelian proportions in a mixed population", Science 28, 49–50 (1908) · J. E. Wigginton, D. J. Cutler and G. R. Abecasis, American Journal of Human Genetics 76, 887–893 (2005)