Hardy–Weinberg Virtual Lab: Selection and Genetic Drift
Updated 2026-10-06
This Hardy–Weinberg virtual lab follows the AP Biology mathematical modeling investigation on Hardy–Weinberg equilibrium. In the AP lab, students build a spreadsheet that calculates allele frequencies generation by generation. Here the simulation does the arithmetic, so class time goes into the question that matters: what keeps a population in equilibrium, and what pushes it out? Students start with a population at equilibrium, calculate genotype frequencies, then add selection against the recessive phenotype and shrink the population to see genetic drift. They come away with p, q and genotype data for three kinds of runs, and a clear link between each Hardy–Weinberg condition and what happens when it is broken. Every number below was read from the simulation.
Curriculum links
- AP Biology: Unit 7 (Natural Selection), topics 7.4, population genetics, and 7.5, Hardy–Weinberg equilibrium (EVO-1), and the AP mathematical modeling investigation on Hardy–Weinberg.
- NGSS: HS-LS4-3, using statistics and probability to explain why organisms with an advantageous heritable trait increase in proportion.
- Simulic is not affiliated with or endorsed by the College Board.
Before the lab (5 min)
Ask: "A population of 1,000 starts with p = 0.6. There is no selection, mating is random, and the population is large. What will p be after 20 generations?" Students choose about 0.6, 1.0, 0.5 or 0, and give a reason. On a class link this is question 1; the simulation unlocks after they answer.
Method in the simulation
The simulation runs 4 generations per second. Pause stops it, Next generation steps once, Reset starts again from the starting p. The Drift button is blue when random sampling of gametes is on. Set the starting allele frequency p in the starting values below the simulation, and N and s with the sliders. The selection coefficient s works against aa: their fitness is 1 − s.
- Equilibrium. p = 0.6, N = 1,000, s = 0, Drift off. Press Reset and let it run past generation 20. Record p, q and the three genotype frequencies.
- A second population. Change p to 0.7 and repeat.
- Selection. p = 0.5, s = 1.00 (aa never reproduce), Drift off. Press Reset. Pause close to generations 10, 20 and 50, and record the generation number and q each time.
- Genetic drift. p = 0.5, N = 20, s = 0, Drift on. Press Reset and run to generation 100. Record whether an allele was lost, and at which generation. Repeat five times.
- Control for drift. Repeat step 4 with N = 1,000.
| Run | p (start) | N | s | Drift | Generation | p | q | AA | Aa | aa |
|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 0.6 | 1,000 | 0 | off | 20 | |||||
| 2 | 0.7 | 1,000 | 0 | off | 20 | |||||
| 3 | 0.5 | 1,000 | 1 | off | ≈ 10 / 20 / 50 | |||||
| 4 | 0.5 | 20 | 0 | on | 100 |
Expected results
Equilibrium. With p = 0.6, s = 0 and Drift off, p stays at 0.600 for every generation. The line shows 0.360 + 0.480 + 0.160 = 1. With p = 0.7 it shows 0.490 + 0.420 + 0.090. Allele and genotype frequencies do not change.
Selection. With s = 1 and p = 0.5, q falls to 0.333 after 1 generation, 0.083 after 10, 0.045 after 20 and 0.019 after 50. In a test run paused at generation 56, q was 0.017. The fall slows down because, once a is rare, almost every copy sits in a heterozygote, where selection cannot see it.
Drift. With N = 20, most runs lose an allele within 100 generations: in about 9 runs out of 10 in our checks, but at a different generation each time. With N = 1,000 and Drift on, p still wanders, usually by less than 0.1 in 20 generations, but no allele is lost.
Questions for students
- Prediction: with p = 0.6, N = 1,000, no selection and Drift off, what will p be after 20 generations?
- You compare a run with s = 0 and a run with s = 0.5. Which settings must be the same?
- p = 0.7, s = 0, Drift off. Using the aa frequency, how many of the 1,000 individuals are heterozygous carriers?
- p = 0.5, s = 1, Drift off. How does q change up to generation 50?
- N = 20, s = 0, Drift on: explain why an allele is lost in some runs, and name the condition broken.
Answers for teachers:
- About 0.6, unchanged.
- Starting p, population size N and the Drift setting.
- aa = 0.09, so q = 0.3, p = 0.7 and 2pq = 0.42: 420 carriers (accepted ± 5).
- It falls fast at first, then more and more slowly, and is still above zero at generation 50.
- Random sampling of gametes in a small population changes p by chance each generation until one allele is lost. The condition broken is a very large population.
Common misconceptions
- "The dominant allele becomes more common over time." Run 1: p stays at 0.6. Dominance doesn't change allele frequencies.
- "Selection quickly removes a harmful recessive allele." Even when aa never reproduce, q is still 0.019 after 50 generations.
- "Drift needs a cause, such as a disaster." In run 4 nothing happens to the population except chance.
Extension
- Mild selection. Repeat run 3 with s = 0.5: q is 0.164 after 10 generations and 0.040 after 50, slower than with s = 1.
- Population size. Compare N = 10, 20 and 50 with Drift on. In our checks, an allele was lost within 100 generations in about 99 %, 89 % and 46 % of runs. Pool the class's runs and compare.
FAQ
Why turn Drift off for the equilibrium runs?
With Drift on, p changes a little every generation by chance, even with N = 1,000. Turning it off gives the ideal, infinitely large population that Hardy–Weinberg assumes, so every student sees exactly p = 0.600.
Can students build the spreadsheet as well?
Yes. A good sequence is: run the simulation first, then build a spreadsheet with p' = (p² + pq) ÷ (1 − s·q²) and check it against the simulation's q for run 3.
Does the simulation model mutation or migration?
No. It models random mating, selection against aa and genetic drift. Discuss mutation and gene flow as the other two conditions.
Related
Genetic drift – Wright–Fisher model, bottleneck and founder effect
Natural selection – changing allele frequency (peppered moth)
For writing number questions with fixed answers, see writing good questions for virtual labs. For more activities, see interactive biology lesson ideas.