AP subjects/AP Biology/Hardy-Weinberg Calculator & Simulator
CED 7.5AP Biology

Hardy-Weinberg Calculator & Simulator

Use this free Hardy-Weinberg calculator to see how a single allele frequency, pp, sets all three genotype frequencies in a population at equilibrium. Move the slider and the bar chart and readout update together, so you can check your own answers to AP Biology problems.

Controls
p

How to use the simulator

The simulator has one control: the allele freq p slider. It runs from 0 to 1 in steps of 0.01, and pp is the frequency of the dominant allele A. The simulator calculates q=1−pq = 1 - p for you.
As you move the slider, three things update:
  • Bar chart. Three bars show the expected genotype frequencies for AA, Aa (heterozygote) and aa, each labelled with its value. The y-axis (genotype frequency) runs from 0 to 1.
  • Readout box. Lists p (freq. of A) and q (freq. of a) to two decimal places, then p2 AA, 2pq Aa and q2 aa to three decimal places.
  • Check line. Under the readout, a line confirms that p+q=1p + q = 1 and p2+2pq+q2=1p^2 + 2pq + q^2 = 1 for every slider position.
The simulator works in frequencies, not head counts. Exam problems usually give you counts, so first turn the count into a frequency (divide by the population size), find pp, and then set the slider to that pp. To get expected numbers of individuals, multiply each genotype frequency by the population size yourself.
Two settings are worth trying. At p=0.50p = 0.50 the heterozygote bar reaches its maximum of 0.500. At p=0.90p = 0.90 (so q=0.10q = 0.10), the aa readout drops to 0.010 while 2pq Aa shows 0.180. Carriers outnumber affected individuals 18 to 1, which is why a rare recessive allele can stay hidden in heterozygotes instead of disappearing.

The equations

Hardy-Weinberg uses two equations. The first covers alleles and the second covers genotypes:
p+q=1p + q = 1
p2+2pq+q2=1p^2 + 2pq + q^2 = 1
  • pp is the frequency of the dominant allele and qq is the frequency of the recessive allele.
  • p2p^2 is the frequency of homozygous dominant individuals (AA).
  • 2pq2pq is the frequency of heterozygotes (Aa). The factor of 2 is there because a heterozygote can get A from the mother and a from the father, or the other way round.
  • q2q^2 is the frequency of homozygous recessive individuals (aa).
These frequencies are only expected if the population meets all five Hardy-Weinberg conditions:
  • No mutation
  • Random mating
  • No natural selection
  • Extremely large population size (no genetic drift)
  • No gene flow (no migration in or out)
If any condition is violated, allele frequencies can change from generation to generation; that change is evolution. The simulator's bars always show the equilibrium prediction, never a real population's frequencies.

Worked example

Problem: In a population of 500 plants, 45 have white flowers, which is the recessive phenotype (aa). Assuming Hardy-Weinberg equilibrium, find the allele frequencies and the expected number of plants with each genotype.
Step 1: Start from the recessive phenotype. Only the aa individuals can be identified by phenotype, so begin with them: q2=45/500=0.09q^2 = 45 / 500 = 0.09.
Step 2: Find q. q=0.09=0.3q = \sqrt{0.09} = 0.3.
Step 3: Find p. p=1−0.3=0.7p = 1 - 0.3 = 0.7.
Step 4: Find the genotype frequencies.
p2=0.72=0.49p^2 = 0.7^2 = 0.49
2pq=2×0.7×0.3=0.422pq = 2 \times 0.7 \times 0.3 = 0.42
q2=0.09q^2 = 0.09
Check: 0.49+0.42+0.09=1.000.49 + 0.42 + 0.09 = 1.00.
Step 5: Convert to numbers of plants.
AA: 0.49×500=2450.49 \times 500 = 245
Aa: 0.42×500=2100.42 \times 500 = 210
aa: 0.09×500=450.09 \times 500 = 45
Total: 245+210+45=500245 + 210 + 45 = 500.
Check it in the simulator: set the slider to 0.70. The readout should show q = 0.30, p2 AA = 0.490, 2pq Aa = 0.420 and q2 aa = 0.090. Purple-flowered plants (AA plus Aa) make up 0.91 of the population, but almost half of them (210 of 455) carry the white allele.

Common mistakes on the AP exam

  • Taking the square root of the dominant phenotype. The dominant phenotype is p2+2pqp^2 + 2pq, not p2p^2, so 0.91\sqrt{0.91} does not give pp. Always start from q2q^2, the recessive phenotype.
  • Mixing up q and q2. If a problem says 9% of individuals are aa, then q2=0.09q^2 = 0.09 and q=0.3q = 0.3, not 0.09. If it says the allele frequency is 0.09, then q=0.09q = 0.09.
  • Forgetting the 2 in 2pq. Using pqpq for heterozygotes makes the three genotype frequencies add up to less than 1. Check that they sum to 1, just as the simulator's check line does.
  • Answering in percent or counts when a frequency is asked for (or the reverse). Read the question for "frequency," "percentage" or "number of individuals" and give that form.
  • Assuming equilibrium without being told to. If observed genotype counts are given, compare them with the Hardy-Weinberg expectation. A mismatch means at least one condition is being violated.
  • Naming a condition vaguely. "The population is not ideal" earns nothing. Name the specific condition (for example, nonrandom mating) and explain how it would change allele or genotype frequencies.

When the AP exam uses this

Hardy-Weinberg is in Unit 7 (Natural Selection), topic 7.5, and both equations appear on the AP Biology formula sheet. Expect calculation questions that start from a recessive phenotype frequency, and conceptual questions that ask which condition a scenario violates. Free-response questions sometimes pair Hardy-Weinberg expected counts with a chi-square test to decide whether a population is evolving.
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.