Population Genetics Explorer

Track a single locus through hundreds of generations under any combination of selection, mutation, drift, and migration. The simulation applies all four forces every generation and renders the resulting allele frequency trajectory, a de Finetti genotype triangle, and a Hardy-Weinberg chi-square check on the starting frequencies.

Allele frequency p over time

0.000.250.500.751.00050100150200GenerationsAllele A frequency p

Genotype frequency triangle (de Finetti)

AAaaAa
start end HWE curve

Results

Initial p
0.5000
Final p
0.5730
Initial H = 2pq
0.5000
Final H = 2pq
0.4893
Dominant evolutionary force
Genetic drift
Small N causes random allele frequency fluctuations.
HWE chi-square test from initial frequencies

Compares observed AA, Aa, aa from your starting p with the random mating expectation (using p estimated from those counts as if it were a sample of N = 100).

GenotypeObservedExpected
AA25.0025.00
Aa50.0050.00
aa25.0025.00
χ² = 0.000 (df = 1)

Selection (relative fitness)

Mutation rates

Migration

Selection step

With genotype fitnesses w(AA), w(Aa), w(aa), allele A frequency after one round of viability selection is

Mutation step

Forward mutation rate μ (A → a) and backward rate ν (a → A) give

Migration step

Each generation a fraction m of the population is replaced by migrants whose allele A frequency is p_source.

Drift step

For finite N, the next generation samples 2N alleles binomially:

With N set to Infinite, drift is skipped and trajectories are deterministic.

Reference Guide

The five Hardy-Weinberg assumptions

A locus stays at p², 2pq, q² genotype frequencies generation after generation only when all five conditions hold.

  • No selection. All genotypes have equal viability and fertility.
  • No mutation. Allele identities are inherited unchanged.
  • No migration. The population is closed to gene flow.
  • Random mating. Mate choice is independent of genotype at this locus.
  • Infinite population size. Allele frequencies are not jostled by sampling.

When any one condition fails, allele frequencies drift away from their starting values. This tool lets you turn each violation on and watch the result.

Evolutionary forces

Each generation the simulator applies forces in this order.

Selection. p=p2wAA+pqwAap2wAA+2pqwAa+q2waap' = \dfrac{p^{2} w_{AA} + pq\, w_{Aa}}{p^{2} w_{AA} + 2pq\, w_{Aa} + q^{2} w_{aa}}
Mutation. p=p(1μ)+(1p)νp'' = p'(1 - \mu) + (1 - p')\,\nu
Migration. p=(1m)p+mpsourcep''' = (1 - m)\, p'' + m\, p_{\text{source}}
Drift. kBinomial(2N,p)k \sim \mathrm{Binomial}(2N, p''')

Fitness, viability, and selection patterns

The fitness sliders set relative survival and reproduction of each genotype. The form of selection determines the long-term outcome.

  • Directional. w(AA) > w(Aa) > w(aa) drives p toward 1.
  • Stabilizing or overdominance. w(Aa) larger than both homozygotes maintains a polymorphism at intermediate p.
  • Underdominance. w(Aa) smaller than both homozygotes pushes p toward whichever boundary it starts closer to and erases variation.
  • Frequency-independent. Fitness values here do not depend on p, only on genotype.

A small fitness difference of 0.01 still moves p substantially over 200 generations when the population is large.

When drift dominates selection

The variance in p from one generation of drift is approximately p(1p)2N\dfrac{p(1-p)}{2N}. Selection coefficient s competes with drift through the product 2Ns.

  • 2Ns much greater than 1. Selection wins. Trajectories are nearly deterministic.
  • 2Ns near 1. Selection and drift are comparable. Outcomes vary across replicates.
  • 2Ns much less than 1. Drift wins. Alleles fix or are lost roughly at random.

Run the 10-replicates button with a small N (around 20 to 50) and equal fitnesses to see drift fix or lose alleles purely by chance.