An allele changes expected reproductive contribution. What happens when the next generation has a finite number of copies?
Let p be the A frequency before selection and q=1-p. Random mating gives genotype probabilities p², 2pq and q². Fitness weighting gives
The next generation is generated by
We use the same fitnesses, population sizes, seeds and plots as the lecture.
library(hpgR)
options(repr.plot.width = 9, repr.plot.height = 3.8)
drawFigure <- function(name, draw, height = 3.6) {
draw()
figureDir <- Sys.getenv("P8149_FIGURE_DIR")
if (nzchar(figureDir)) {
dir.create(figureDir, recursive = TRUE, showWarnings = FALSE)
pdf(file.path(figureDir, paste0(name, ".pdf")), width = 9,
height = height, family = "Helvetica", pointsize = 12,
useDingbats = FALSE)
tryCatch(draw(), finally = dev.off())
}
}
Expected trajectories under selection¶
Pritchard’s Fig. 2.81 starts the tracked allele at 0.0001 or 0.20. For each selection coefficient , use fitnesses in tracked-copy order. Apply the expected frequency update each generation. The curves show the deterministic prediction for those fitnesses.
The first point is numbered 1, as in the textbook. The plots can also be exported as lecture PDFs by setting the environment variable P8149_FIGURE_DIR.
drawFigure("selection_pritchard_2_81", function() {
par(mfrow = c(1, 2), mar = c(4.2, 4.3, 2.4, 1.6))
for (p0 in c(.0001, .20)) {
lastGeneration <- if (p0 == .0001) 6000L else 2000L
s <- c(.01, .005, -.01)
paths <- vapply(s, function(effect) {
selectionFrequencies(p0, c(1 + effect, 1 + effect / 2, 1),
lastGeneration - 1L)
}, numeric(lastGeneration))
colors <- c("#111111", "#265991", "#B33B32")
matplot(seq_len(lastGeneration), paths, type = "l", ylim = c(0, 1),
xlim = c(0, lastGeneration), xaxs = "i", lwd = 1.8, lty = 1,
col = colors, xlab = "Generation", ylab = "A frequency",
main = paste("Starting frequency =", format(p0, scientific = FALSE)))
if (p0 == .0001) {
legend("bottomright", paste("s =", s), inset = c(.03, .10),
col = colors, lty = 1,
lwd = 1.8, bty = "n")
}
}
})
One generation¶
Set p=0.10 and fitnesses (1.10, 1.05, 1.00), ordered AA, Aa, aa. Compare 3,000 independent draws at Ne=20 and Ne=200. Blue marks the conditional expectation; red dashes mark the initial frequency.
p <- .1
w <- c(1.10, 1.05, 1)
pSel <- selectedFrequency(p, w)
set.seed(11001)
draws <- lapply(c(20, 200), function(Ne) rbinom(3000, 2 * Ne, pSel) / (2 * Ne))
drawFigure("selection_one_generation", function() {
par(mfrow = c(1, 2), mar = c(4.2, 4.3, 2.4, .8))
for (i in seq_along(draws)) {
hist(draws[[i]], breaks = if (i == 1) seq(-.0125, 1.0125, .025) else 35,
col = "#CCDDED", border = "white",
main = paste("Ne =", c(20, 200)[i]), xlab = "Next A frequency",
ylab = "Replicate populations", xlim = c(0, .35))
abline(v = p, col = "#B33B32", lty = 2, lwd = 2)
abline(v = pSel, col = "#265991", lwd = 2)
}
}, 3.8)

The finite-population model supplies exact probabilities to check the simulation. Here we compare the observed mean with the binomial mean and calculate the chance of a decline.
for (i in seq_along(draws)) {
Ne <- c(20, 200)[i]
monteCarloSE <- sqrt(pSel * (1 - pSel) / (2 * Ne * 3000))
stopifnot(abs(mean(draws[[i]]) - pSel) < 5 * monteCarloSE)
}
c(pSel = pSel,
declineNe20 = selectionDeclineProbability(20, p, pSel),
declineNe200 = selectionDeclineProbability(200, p, pSel))
Repeat reproduction for 150 generations¶
Keep the same fitnesses and p0=0.10. Each blue line is one of 40 independent histories; red is the deterministic recurrence. At the same starting frequency, the two population sizes begin with different allele counts.
generations <- 150L
replicates <- 40L
set.seed(11002)
paths <- lapply(c(20, 200), function(Ne) {
result <- matrix(p, nrow = generations + 1L, ncol = replicates)
for (generation in seq_len(generations)) {
probabilities <- vapply(result[generation, ], selectedFrequency, numeric(1), w = w)
result[generation + 1L, ] <- rbinom(replicates, 2 * Ne, probabilities) / (2 * Ne)
}
result
})
reference <- selectionFrequencies(p, w, generations)
drawFigure("selection_replicate_paths", function() {
par(mfrow = c(1, 2), mar = c(4.2, 4.3, 2.4, .8))
for (i in seq_along(paths)) {
matplot(0:generations, paths[[i]], type = "l", lty = 1, lwd = .7,
col = "#26599155", ylim = c(0, 1),
xlab = "Generation", ylab = "A frequency",
main = paste("Ne =", c(20, 200)[i]))
lines(0:generations, reference, col = "#B33B32", lwd = 2.5)
}
})

The recurrence supplies the conditional update at each current frequency. Finite populations can follow different paths, including loss of A. The lecture’s single-copy fixation discussion changes the starting count to one.
Model sources: Pritchard, An Owner’s Guide to the Human Genome, Section 2.5; Gorroochurn, Population Genetics Notes, Sections 5.5–5.7. Fitness values are illustrative.