AP subjects/AP Biology/Natural Selection Simulator
CED 7.2AP Biology

Natural Selection Simulator

Use this free natural selection simulator to watch the frequency of an allele, pp, change over many generations when one genotype survives and reproduces better than the others. Pick a type of selection, set its strength, and compare the result with the flat line you get with no selection, the Hardy-Weinberg case.

gap-fill addition (Unit 7)

Controls
selection-typestart-psgenerations

How to use the simulator

The model follows one gene with two alleles, A and a. Each generation, genotypes survive and reproduce at different rates, and the simulator calculates the new frequency of A. The controls are:
  • Selection menu: Directional (favor AA), Stabilizing (favor Aa) or Disruptive (favor AA & aa). It opens on Directional.
  • start p (of A) slider. This sets the starting frequency of A. It runs from 0.05 to 0.95 in steps of 0.05 and starts at 0.30.
  • selection strength s slider. s is the fitness cost to the genotypes that are not favored. It runs from 0 to 1 in steps of 0.05 and starts at 0.40.
  • generations N slider. It runs from 10 to 100 in steps of 5 and starts at 60.
The top graph plots Allele frequency p (of A) against Generation, with a dashed gridline at 0.50. Below it, a bar chart compares genotype frequencies for AA, Aa and aa. Dashed outlines show generation 0, and solid bars show the final generation, each labelled with its value. Favored genotypes are drawn in green. These bars are Hardy-Weinberg proportions calculated from p at the start and at the end.
Under the sliders, the result line gives Final p and q to two decimal places, plus a sentence describing the outcome.
The menu sets the relative fitness of each genotype:
  • Directional: AA = 1, Aa = 1 − s/2, aa = 1 − s.
  • Stabilizing: AA = 1 − s, Aa = 1, aa = 1 − s.
  • Disruptive: AA = 1, Aa = 1 − s, aa = 1.
With s = 0 every genotype has a fitness of 1, so whatever you choose in the menu, p stays exactly where it started.

The equations

The simulator starts each generation with Hardy-Weinberg genotype frequencies p2p^2, 2pq2pq and q2q^2, where q=1−pq = 1 - p. It weights each by its relative fitness ww. The mean fitness of the population is
wˉ=p2wAA+2pq wAa+q2waa\bar{w} = p^2 w_{AA} + 2pq\,w_{Aa} + q^2 w_{aa}
and the frequency of A in the next generation is
p′=p2wAA+pq wAawˉp' = \frac{p^2 w_{AA} + pq\,w_{Aa}}{\bar{w}}
The numerator counts the A alleles carried by survivors: all of the alleles in AA individuals and half of those in Aa. These equations go beyond the AP course; they show what the graph calculates.
The key idea is what the AP course calls natural selection. Individuals vary, part of that variation is heritable, and some heritable variants survive and reproduce more than others in a given environment. Over generations the favored alleles become more common. Because selection works on phenotypes, it changes allele frequencies only indirectly.
A note on names. In the AP course, directional, stabilizing and disruptive selection describe how the distribution of a trait shifts: toward one extreme, toward the middle, or toward both extremes. This simulator maps those ideas onto a single gene, using the heterozygote to stand for the middle value. Its Stabilizing setting is heterozygote advantage, which keeps both alleles in the population. Its Disruptive setting is heterozygote disadvantage, which pushes p toward 0 or 1.

Worked example

Problem: In a population of insects, p = 0.30 for allele A. Pesticide spraying gives relative fitnesses AA = 1, Aa = 0.8 and aa = 0.6 (directional selection with s = 0.40). Find p after one generation.
Step 1: Starting genotype frequencies. p2=0.09p^2 = 0.09, 2pq=2(0.3)(0.7)=0.422pq = 2(0.3)(0.7) = 0.42, q2=0.49q^2 = 0.49.
Step 2: Weight by fitness. AA: 0.09×1=0.090.09 \times 1 = 0.09. Aa: 0.42×0.8=0.3360.42 \times 0.8 = 0.336. aa: 0.49×0.6=0.2940.49 \times 0.6 = 0.294. Mean fitness: wˉ=0.09+0.336+0.294=0.72\bar{w} = 0.09 + 0.336 + 0.294 = 0.72.
Step 3: New allele frequency. A alleles among survivors: 0.09+12(0.336)=0.2580.09 + \tfrac{1}{2}(0.336) = 0.258. So p′=0.258/0.72≈0.358p' = 0.258 / 0.72 \approx 0.358.
Interpret: one generation of selection raised p from 0.30 to about 0.36.
Check it in the simulator: choose Directional, set start p to 0.30, s to 0.40 and N to 10. The result line reads Final p = 0.84 (q = 0.16). Raise N to 60 and Final p reads 1.00: allele A has effectively reached fixation.

Common mistakes on the AP exam

  • Saying individuals evolve. An individual's genotype does not change. The population evolves as allele frequencies shift from one generation to the next.
  • Saying organisms develop traits because they need them. The variation must already exist and be heritable. Selection only changes how common each variant becomes.
  • Equating fitness with strength. Fitness is reproductive success: how many offspring an individual leaves, relative to others.
  • Assuming selection always removes an allele. Under heterozygote advantage both alleles persist. Sickle-cell anemia in regions with malaria is the classic example.
  • Mixing up the selection types. Name which phenotypes are favored, then say how the trait's distribution or the allele frequency will shift.

When the AP exam uses this

Natural selection is topic 7.2 in Unit 7 (Natural Selection), and it links directly to Hardy-Weinberg in topic 7.5, where no selection is one of the conditions for equilibrium. Expect to explain how an environmental change shifts allele frequencies, interpret a graph of allele frequency over time, and identify directional, stabilizing or disruptive selection from a trait distribution.
Embed this simulator on your class page

Free for classroom use. Paste this into your site, LMS page or blog; keep the credit link under it.