Natural Selection and Population Genetics Simulator
Equations in this simulation
| p | frequency of the dark allele A | Starting frequency of the dark allele p | |
|---|---|---|---|
| q | frequency of the light allele a | q = 1 − p | |
| p², 2pq, q² | expected shares of AA, Aa and aa | Hardy–Weinberg: true for random mating with no selection, drift, mutation or migration; compared below with the shares counted in the population |
With the current values:
| w | fitness of each genotype | the share that survives the birds: 1 for a well camouflaged moth, 1 − s for a conspicuous one | |
|---|---|---|---|
| w̄ | mean fitness | ||
| p′ | expected frequency next generation | what selection alone would give; the real population also drifts by chance |
With the current values:
| N | Population size N | each generation is 2N gene copies drawn at random from the parents; a small population wanders and can lose an allele entirely |
|---|
With the current values:
| χ² | test of Hardy–Weinberg | above 3.84 (one degree of freedom) the genotype counts are significantly off Hardy–Weinberg, at the 5% level |
|---|
With the current values:
How to use the natural selection simulator
- A population of moths rests on tree bark. Each has two copies of a color gene: A for dark and a for light. Birds hunt the ones that stand out against the bark, the selection strength setting how many of those are eaten; the survivors mate at random and the next generation takes their place.
- Start with few dark moths on light bark and watch the dark allele fade; switch the bark to dark, as soot did in industrial England, and watch it take over in a few dozen generations. The chart shows the dark allele frequency, against the gray line selection alone would give.
- Set the selection strength to 0 and the population large: the genotypes match the Hardy–Weinberg proportions p², 2pq and q², and the χ² test agrees. Then add selection, or make the population small so that chance drift takes over, and watch the equilibrium break. The Hardy-Weinberg Calculator does the same arithmetic for counts you have, and the Punnett Square shows the crosses behind it.
Frequently asked questions
What is Hardy–Weinberg equilibrium?
In a large population with random mating and no selection, mutation, migration or drift, allele frequencies stay the same from one generation to the next, and the genotypes settle at p² AA, 2pq Aa and q² aa. It is the null model of population genetics: when a real population departs from it, one of those conditions is not being met.
How does natural selection change allele frequencies?
Individuals with some genotypes survive or reproduce better, so their alleles are passed on more often. If dark moths survive 30% better than light ones on dark bark, the dark allele frequency rises a little each generation, by an amount that depends on p, q and whether the allele is dominant. A rare recessive allele is nearly invisible to selection, because almost all its copies hide in heterozygotes.
What is genetic drift?
Random change in allele frequencies from the luck of which individuals happen to breed. Each generation is a sample of the last, and in a small population that sample can be far off: the standard deviation of the change is √(pq/2N). Drift can fix or lose an allele with no selection at all, which is why small, isolated populations lose genetic variation.
Is the peppered moth story true?
Yes. In industrial Britain the dark form of the peppered moth went from rare in the 1840s to over 90% around Manchester by 1900, as soot killed the lichens and darkened the trees, and fell back after clean air laws in the 1950s. Field studies, including a large one by Michael Majerus published in 2012, confirmed that birds eat the conspicuous moths more.
It says WebGL is turned off.
The 3D view needs WebGL, which every current browser has. It can be switched off by hardware acceleration being disabled in the browser settings, or by a very old graphics driver. Turn hardware acceleration on, or try another browser.
Is anything uploaded?
No. The simulation is drawn by your own browser with WebGL; nothing is sent anywhere, and it keeps working offline once the page has loaded.