AP® Biology simulator

Hardy-Weinberg and genetic drift

Watch allele frequencies change by chance, selection and migration over generations.

About this tool

Follow one gene with two alleles, A and a, through many generations. Choose the population size, then add selection, mutation, migrants or non-random mating, and run several populations side by side. Watch the frequency of A wander, settle or vanish, compare each generation's genotypes with the Hardy-Weinberg expectation, and test the difference with chi-square. Every random run comes from a seed you can see and type, so anyone with the same seed gets the same result. The questions below use the same model.

How it works

The gene has two alleles: A, with frequency p, and a, with frequency q = 1 − p. Each individual is AA, Aa or aa. If nothing changes the allele frequencies and mating is random, the genotypes settle at the Hardy-Weinberg frequencies p², 2pq and q², and p stays the same from one generation to the next.

p + q = 1 · p² + 2pq + q² = 1

Each generation the model takes these steps, in this order:

  1. Selection. Each genotype has a fitness from 0 to 1: its share of offspring compared with the others. An aa fitness of 0 means aa individuals leave no offspring. The adults' alleles are counted into the gene pool in proportion to their genotype's fitness.
  2. Mutation. A fraction u of A alleles in the gene pool become a, and a fraction v of a alleles become A.
  3. Migration (gene flow). A fraction m of the gene pool is replaced by alleles from migrants, whose frequency of A is the donor p.
  4. Mating. With random mating the new zygotes are p², 2pq and q². Non-random mating is set by F, the share of matings between relatives: it makes AA p²(1 − F) + pF, Aa 2pq(1 − F) and aa q²(1 − F) + qF, so there are fewer heterozygotes, but p itself does not change.
  5. Genetic drift. Only N of the zygotes become the next generation's adults, picked at random one by one (a Wright-Fisher population). By chance, the adults' allele frequency differs a little from the zygotes'. In a very large population the adults match the zygotes exactly, so there is no drift and every replicate is identical.
  • Generation 0 is set, not drawn: N adults with p as chosen and the genotypes of step 4, rounded to whole individuals, the same in every replicate.
  • Fixed and lost. When p reaches 1, A is fixed (every allele is A); when p reaches 0, A is lost. With no mutation or migration a fixed or lost allele never comes back.
  • Bottleneck and founder event. A bottleneck shrinks the population to a few adults for some generations, then it returns to N. A founder event is a one-generation bottleneck: a few individuals start a new population, which is the one the graph then follows.
  • Random numbers. The seed starts a generator that gives the same numbers every time. Replicate 1 uses the seed, and each later replicate its own stream from it, so the same seed and settings always give the same runs, and adding replicates does not change the first ones.
  • Chi-square against Hardy-Weinberg. For the generation you read, the expected counts are N·p², N·2pq and N·q², using p from the same adults. χ² = Σ (o − e)² / e. With three genotypes the usual rule gives 3 − 1 = 2 degrees of freedom (critical value 5.99 at p = 0.05); some statistics books use 1 because p was estimated from the same counts (critical value 3.84). The tool shows both decisions; when they differ, say which rule you used. With an expected count below 5 the test is unreliable.
  • Fitness, mutation and migration act on the gene pool, not on chance, so with a very large population (no drift) the model has no randomness at all.

Notes for this topic: Hardy-Weinberg Equilibrium