Hardy-Weinberg and Genetic Drift
Simulate allele frequencies across generations and see how population size and selection break equilibrium
Diploid individuals, so 2N allele copies
Selection
- Generation
- 0 / 100
- p in population 1
- 0.500
- Mean p
- 0.500
- Infinite population p
- 0.500
- Fixed (p = 1)
- 0 of 10
- Lost (p = 0)
- 0 of 10
- Mean 2pq
- 0.500
- Expected 2pq (drift)
- 0.500
- Population 1 (selected; tap a line to pick another)
- Starting frequency: an infinite population would stay here
Population 1, generation 0: observed genotypes against Hardy-Weinberg p², 2pq, q² for p = 0.500
Generation 0 is the founding population. Run or step forward to breed offspring by random mating.
Bars: observed genotype shares. Black ticks: Hardy-Weinberg expectation from this generation's allele frequency. Fitness: AA 1.000, Aa 1.000, aa 1.000.
Hardy-Weinberg equilibrium and what breaks it
Take one gene with two alleles, A with frequency p and a with frequency q = 1 − p. If individuals mate at random, two random gametes meet in every offspring, so the genotype frequencies are AA = p², Aa = 2pq and aa = q². This is the Hardy-Weinberg principle: in a very large population with random mating and no selection, mutation or migration, allele and genotype frequencies stay the same from one generation to the next.
Real populations are finite. The visualizer uses the Wright-Fisher model: each generation of N diploid individuals is formed by drawing 2N allele copies at random from the previous generation, after selection has acted. The sampling makes p take a random walk called genetic drift. Once p reaches 0 or 1 the allele is lost or fixed and, with no mutation, it stays there.
Selection adds a steady push. When aa individuals survive less well, A rises every generation. When heterozygotes are fittest, both alleles are held at a stable balance.
Random mating
Genetic drift
Natural selection
Population size
Key formulas
Hardy-Weinberg proportions
p² + 2pq + q² = 1
- p
- frequency of allele A
- q
- frequency of allele a, so p + q = 1
Allele frequency from genotype counts
p = (2 × N_AA + N_Aa) / (2N)
- N
- number of diploid individuals
Genetic drift in one generation
E[p′] = p, Var(p′) = p(1 − p) / (2N)
Loss of heterozygosity and fixation under drift
H_t = H_0 (1 − 1/(2N))ᵗ, P(A fixes) = p_0
- H
- heterozygosity 2pq, averaged over many populations
Selection
p′ = (p² w_AA + pq w_Aa) / w̄, w̄ = p² w_AA + 2pq w_Aa + q² w_aa
- w
- relative fitness of each genotype
- w̄
- mean fitness of the population
Heterozygote advantage
p̂ = t / (s + t)
- s, t
- fitness costs, with fitnesses AA = 1 − s, Aa = 1 and aa = 1 − t
Worked example: cystic fibrosis carriers
Cystic fibrosis is recessive. In populations of northern European descent about 1 baby in 2,500 is affected. Assuming Hardy-Weinberg proportions, how common are carriers?
Carriers are about 98 times as common as affected people, because most copies of a rare recessive allele sit in heterozygotes.
| Quantity | Formula | Value |
|---|---|---|
| Affected (aa) | q² | 1/2,500 = 0.0004 |
| Frequency of a | q = √0.0004 | 0.02 |
| Frequency of A | p = 1 − q | 0.98 |
| Carriers (Aa) | 2pq | 0.0392, about 1 in 26 |
| Not carrying a (AA) | p² | 0.9604 |
The same fact explains why selection against a rare recessive is slow: aa individuals are so rare that selection barely touches the a allele, which is what the flattening curve in the selection step of the tour shows.
How to use this visualizer
- 1Set the population size N, the starting frequency p of allele A, the number of generations and how many replicate populations to run side by side.
- 2Press Run to breed generation after generation. Each coloured line is one population; the dashed line is what an infinite population would do.
- 3Tap a line to select that population. The bars below compare its observed AA, Aa and aa shares with p², 2pq and q² for the current generation.
- 4Watch the Fixed and Lost counts, and compare Mean 2pq with Expected 2pq (drift) to see heterozygosity drain away.
- 5Turn on selection against aa, or set custom fitnesses, and compare small and large N.
Real-world applications
Carrier frequencies
Conservation genetics
Sickle-cell and malaria
Founder effects
Equilibrium is a null model
Practice problems
Problem 1: From phenotype to genotypes
Show solutionHide solution
q² = 0.16, so q = 0.4
p = 1 − 0.4 = 0.6
Carriers: 2pq = 2 × 0.6 × 0.4 = 0.48
Homozygous dominant: p² = 0.36
p = 0.6, q = 0.4; 48% are carriers
Problem 2: Drift erodes diversity
Show solutionHide solution
H_0 = 2 × 0.5 × 0.5 = 0.5
1 − 1/(2N) = 1 − 1/100 = 0.99
H_50 = 0.5 × 0.99⁵⁰ = 0.5 × 0.605 = 0.302
About 0.302, so roughly 40% of the heterozygosity is gone
Problem 3: One generation of selection
Show solutionHide solution
w̄ = 0.25 × 1 + 0.5 × 1 + 0.25 × 0.8 = 0.95
p′ = (p² w_AA + pq w_Aa) / w̄ = (0.25 + 0.25) / 0.95
p′ ≈ 0.526, a rise of about 0.026 in one generation
Spotted a mistake on this page?
Wrong formula, broken animation or confusing wording. Tell us and we will fix it.