Natural Selection & Hardy-Weinberg · Guide · glidepathscience.org
GuideNatural Selection & Hardy-Weinberg
Contents
This Guide explains the ideas and equations behind every Walkthrough step, Concept Challenge question and Predict round. Part 1 prepares the Intro track and Part 2 the Advanced track. Each section works an example that is not one of the sim’s own problems.
Part 1 · The essentials
Math you’ll need: fractions, decimals and percents, squares and square roots, and a weighted average.
Evolution as a change in allele frequency
Natural selection needs three things, as Darwin saw: individuals vary, the variation is inherited, and it changes the chance of surviving or reproducing. Give a population all three and the next generation differs from this one, not because any individual changed, but because the individuals that breed are not a random sample. A beetle born light stays light all its life; a population of beetles can get darker.
Genetics turns this into a number. Each beetle carries two copies of a gene, its two alleles. With two alleles, A and a, there are three genotypes, AA, Aa and aa. If A is dominant, an Aa beetle looks like an AA one; the recessive a shows only in aa. The allele frequency $p$ is the share of all the gene copies in the population that are A, and $q = 1 − p$ is the share that are a. Count alleles, two per individual:
$p = (2n_{AA} + n_{Aa})/2N$ $q = 1 − p$
In this language, evolution is a change in allele frequency from one generation to the next.
Selection changes p
Selection acts on individuals, but what it changes is the population’s $p$. Remove some individuals before they breed and count the alleles of the survivors: if the ones removed were mostly of one genotype, the survivors’ $p$ differs from the population’s, and the next generation inherits the survivors’ alleles.
Repeat this every generation and $p$ moves steadily. Against a recessive allele, though, selection slows as the allele gets rare: when $q$ is small, aa individuals are a share $q^2$, tiny, while the heterozygotes, a share $2pq$, carry almost every copy of a and look like AA. The bird cannot find what it cannot see, so a harmful recessive allele is pushed down quickly at first and then lingers.
Hardy-Weinberg: the population that does not evolve
Suppose nothing acts. With random mating, every egg and sperm is a random draw from the population’s alleles: A with probability $p$, a with probability $q$. An offspring is AA with probability $p × p$, aa with $q × q$, and Aa with $2pq$, since the A can come from either parent. The three shares add to 1:
$p^2 + 2pq + q^2 = 1$
These offspring pass on alleles in the same proportions, so $p$ and the genotype shares stay the same in every generation. This is the Hardy-Weinberg principle. It holds under five conditions: no selection, no mutation, no migration, random mating, and a population large enough that chance does not matter. Each force in this sim breaks one of them, which is why Hardy-Weinberg is the baseline every change is measured against.
A common mistake is to think a dominant allele spreads because it is dominant. Dominance decides what a heterozygote looks like, not how often an allele is passed on; with nothing acting, a rare dominant allele stays rare. (The 3:1 ratio belongs to one cross of two heterozygotes, not to a population.)
Hardy-Weinberg also lets you see hidden carriers. Only aa individuals show a recessive trait, and their share is $q^2$, so $q$ is its square root.
Genetic drift: chance in small populations
Even with nothing acting, a real population is finite. The next generation’s alleles are a sample of the parents’, and a sample is never exactly the bag it was drawn from: like ten coin tosses, it can land 7 to 3. This random change in $p$ is genetic drift. It has no direction, up in one population and down in the next, and it is large in small populations and tiny in large ones, where the chances average out.
Drift has one-way doors. Once $p$ reaches 0 the allele is lost, and once it reaches 1 it is fixed; with no mutation or migration nothing brings the other allele back. Given time, every small population fixes one allele or the other, and loses its genetic variation on the way.
Gene flow, mutation, and telling the forces apart
Gene flow moves alleles between populations. If a share $m$ of the breeders each generation are migrants from a source with frequency $p_m$, the new frequency is a weighted average of residents and newcomers:
$p′ = (1 − m)\,p + m\,p_m$
Mutation makes new alleles, but typically at one copy in 100,000 to 1,000,000 per gene per generation; on its own it changes $p$ very slowly. It matters as the source of all variation, and where it balances selection.
| Force | What it does to p | The pattern |
|---|---|---|
| selection | pushes it one way | populations move together, even large ones |
| drift | moves it at random | small populations scatter; some fix, some lose |
| gene flow | pulls it toward the source | connected populations become alike |
| mutation | nudges it slowly | barely visible over tens of generations |
| none (Hardy-Weinberg) | leaves it alone | flat |
Part 2 · Going further
Math you’ll need: everything in Part 1, plus powers and exponentials, the χ² statistic, a standard deviation and a harmonic mean.
Testing Hardy-Weinberg: χ², and what departures mean
Hardy-Weinberg proportions at one autosomal gene are reached in a single generation of random mating, whatever the parents’ genotypes, because offspring depend only on the gamete frequencies. So a population far from them now is a clue that something keeps it away.
To test a sample, estimate $\hat p$ from its own counts, compute the expected counts $N\hat p^2$, $2N\hat p\hat q$ and $N\hat q^2$, and add up the squared gaps relative to what was expected:
$χ^2 = \sum (O − E)^2/E$
The degrees of freedom are the classes less one, less one for each parameter estimated from the data: 3 − 1 − 1 = 1. With one degree of freedom, χ² above 3.84 would arise by chance less than 5 % of the time, so the sample departs from Hardy-Weinberg at the 5 % level. A χ² below 3.84 is no evidence against Hardy-Weinberg; it does not prove the population is at it. And a population truly at Hardy-Weinberg still gives χ² above 3.84 in one sample in twenty.
The chi-square curve is an approximation that needs every expected count to be at least about 5. A small sample or a rare allele breaks it: 18 AA, 2 Aa and 0 aa give $E$ = 18.05, 1.90, 0.05, and χ²’s $P$ = 0.81 means little. The exact test (Wigginton, Cutler and Abecasis, 2005) needs no approximation: with the sample size and the number of each allele fixed, only the heterozygote count can vary, and Hardy-Weinberg gives each possible count its chance; $P$ adds the chances of every count no more likely than the one observed. Here the 2 copies of a are either in two heterozygotes (chance 0.974) or in one aa (0.026), so $P$ = 1. A sample with one allele only (20 AA) cannot be tested at all: Hardy-Weinberg predicts all AA, whatever the population. The Hardy-Weinberg Check uses χ² when every expected count is at least 5 and the exact test otherwise.
Too few heterozygotes points to non-random mating or a mixed sample. With inbreeding coefficient $F$, the genotype shares are $p^2 + Fpq$, $2pq(1 − F)$ and $q^2 + Fpq$: a share $F$ of the heterozygotes is replaced by homozygotes, half each, so $p$ does not change. (With $F$ = 0.1 and $p$ = 0.3, Aa is 0.42 × 0.9 = 0.378 instead of 0.42.) Pooling two subpopulations with different $p$ also gives a deficit, the Wahlund effect. Too many heterozygotes among adults points to selection that favors them.
Fitness, w̄ and heterozygote advantage
Give each genotype a relative fitness $w$, its chance of surviving to breed compared with the best. Weighting the fitnesses by the genotype shares gives the mean fitness, and the A alleles among the survivors give the next generation’s $p$ (with no drift):
$\bar w = p^2w_{AA} + 2pq\,w_{Aa} + q^2w_{aa}$
$p′ = (p^2w_{AA} + pq\,w_{Aa})/\bar w$
Each heterozygote carries one A of two, hence $pq\,w_{Aa}$ and not $2pq\,w_{Aa}$. Subtracting gives the change, $Δp = pq[p(w_{AA} − w_{Aa}) + q(w_{Aa} − w_{aa})]/\bar w$, which vanishes at $p$ = 0 and 1 and wherever the bracket is zero.
When the heterozygote is fittest, write $w_{AA} = 1 − s$, $w_{Aa} = 1$ and $w_{aa} = 1 − t$. The bracket is zero at a stable equilibrium that keeps both alleles, a balanced polymorphism:
$\hat p = t/(s + t)$ $\hat q = s/(s + t)$
The classic case is sickle-cell hemoglobin where malaria is common: carriers of one sickle allele are partly protected from malaria, while people with two have sickle-cell disease. The sim’s fitnesses for it (0.88, 1, 0.14) are illustrative.
The arithmetic of drift
In the Wright-Fisher model the next generation’s 2$N$ alleles are drawn independently, each A with probability $p$, so the number of A copies is binomial and
$\mathrm{SD} = \sqrt{pq/2N}$
is the standard deviation of $p$ after one generation. For $N$ = 200 at $p$ = 0.5 it is √(0.25/400) = 0.025. Drift does not change $p$ on average, so by symmetry each of the 2$N$ copies is equally likely to become the ancestor of all: an allele with drift alone is fixed with probability equal to its frequency, $p_0$. The spread across replicate populations grows until each is fixed or lost.
Heterozygosity, $H = 2pq$, falls by the factor $(1 − 1/2N)$ each generation:
$H_t = H_0(1 − 1/2N)^t$
In a population of 500, 100 generations leave $H$ = 0.5 × 0.999¹⁰⁰ = 0.452 of an initial 0.5; a population of 20 loses most of its variation in that time.
Real populations change size. Drift adds up as $1/N$ per generation, so over $t$ generations they drift like a constant population of the harmonic mean, the effective size:
$N_e = t/\sum 1/N_i$
Sizes of 2,000, 2,000, 2,000 and 100 give $N_e$ = 4/(3/2,000 + 1/100) = 348, far below the average of 1,525: a bottleneck dominates.
Selection and drift together decide the fate of a new mutation. For a new copy ($p_0 = 1/2N$) with an additive advantage $s$, Kimura’s diffusion result is $u = (1 − e^{−4Nsp_0})/(1 − e^{−4Ns})$, close to $2s$ when $4Ns$ is large. For $N$ = 1,000 and $s$ = 0.005, $u$ = 0.00995, against 1/2$N$ = 0.0005 for a neutral copy: twenty times better, yet 99 % of such mutations are lost while still rare. When $4Ns$ is much less than 1, the allele behaves almost as if neutral.
Mutation-selection balance
A harmful allele made by mutation at rate $μ$ per gamete per generation and removed by selection settles where the two balance. For a recessive allele selection acts only on aa, a share $q^2$, removing about $sq^2$ copies per generation; setting that equal to $μ$ gives
$\hat q ≈ \sqrt{μ/s}$
far above the $μ/s$ of a dominant harmful allele, which selection sees in every carrier.
Gene flow over many generations
Each generation, gene flow from a source closes a fraction $m$ of the gap between a population and the source, so the gap is multiplied by $(1 − m)$ every generation:
$p_t = p_m + (p_0 − p_m)(1 − m)^t$
A little migration goes a long way. In idealized migration–drift models (many equal populations exchanging migrants at random, no selection), about one migrant that actually breeds per generation, $Nm ≈ 1$, is enough to keep drift from strongly separating their allele frequencies. It is a rule of thumb, not a guarantee: it does not stop an allele from being lost or fixed, and in real populations, with unequal sizes, migrants that breed less than residents, selection and structure, one migrant a generation can be too few (Mills & Allendorf 1996). This sim has a simpler model, one-way immigration from a source of fixed $p_m$, so it shows gene flow pulling $p$ toward the source rather than testing that rule.
Reference
Common mistakes
Part 1
- Saying individuals evolve. Populations evolve; an individual keeps the alleles it was born with.
- Counting beetles instead of alleles: $p$ is $(2n_{AA} + n_{Aa})/2N$, not the share that looks dark.
- Forgetting that an eaten aa beetle takes two a alleles with it.
- Taking the recessive share as $q$: it is $q^2$, so take its square root first.
- Writing $pq$ for the heterozygotes: an Aa can get A from either parent, so it is $2pq$.
- Believing dominant alleles spread by themselves.
- Thinking drift has a direction, or that it matters as much in large populations as in small ones.
Part 2
- Giving the Hardy-Weinberg χ² two degrees of freedom: estimating $\hat p$ costs one more.
- Reading a χ² below 3.84 as proof of Hardy-Weinberg.
- Using $2pq\,w_{Aa}$ in the numerator of $p′$.
- Averaging population sizes arithmetically instead of harmonically for $N_e$.
- Using $μ/s$, the dominant case, for a recessive allele’s balance.
- Expecting a beneficial mutation to be fixed for sure: its chance is about $2s$.
The equation sheet
| Part 1 | |
|---|---|
| allele frequency | $p = (2n_{AA} + n_{Aa})/2N$ |
| the other allele | $q = 1 − p$ |
| Hardy-Weinberg shares | $p^2 + 2pq + q^2 = 1$ |
| gene flow, one generation | $p′ = (1 − m)\,p + m\,p_m$ |
| Part 2 | |
|---|---|
| χ² (df = 1, 5 %: 3.84) | $χ^2 = \sum (O − E)^2/E$ |
| mean fitness | $\bar w = p^2w_{AA} + 2pq\,w_{Aa} + q^2w_{aa}$ |
| after selection | $p′ = (p^2w_{AA} + pq\,w_{Aa})/\bar w$ |
| heterozygote advantage | $\hat p = t/(s + t)$ |
| drift, one generation | $\mathrm{SD} = \sqrt{pq/2N}$ |
| heterozygosity | $H_t = H_0(1 − 1/2N)^t$ |
| effective size | $N_e = t/\sum 1/N_i$ |
| mutation-selection (recessive) | $\hat q ≈ \sqrt{μ/s}$ |
| gene flow, $t$ generations | $p_t = p_m + (p_0 − p_m)(1 − m)^t$ |
| inbreeding | Aa: $2pq(1 − F)$ |
$p$, $q$: frequencies of A and a; $n$: counts; $N$: population size; $m$: share of migrants; $p_m$: the source’s frequency; $w$: relative fitness; $s$, $t$: selection against AA and aa; $H$: heterozygosity; $N_e$: effective size; $μ$: mutation rate; $F$: inbreeding coefficient; $O$, $E$: observed and expected counts.
Sources and further reading
- OpenStax, Biology 2e, the chapter on the evolution of populations (open textbook, CC BY-NC-SA 4.0, openstax.org), for population genetics at the Intro level.
- The Hardy-Weinberg principle (Hardy and Weinberg, 1908), the Wright-Fisher model of drift and Kimura’s fixation probability (1962) are covered in any population-genetics text.
- This sim’s Field Manual (H) sets out its model and what it leaves out.
Natural Selection & Hardy-Weinberg v1.3 · © 2026 Dr. David Meier · CC BY-NC-SA 4.0 · glidepathscience.org