--- title: "Chapter 3" --- Figure 3.5 Pueblo lineage ```{r} ``` A simple model for allel fixation Figure 3.13 ```{r} # drift vs selection set.seed(1) N <- 10000 # population size gens <- 200 # generations p0 <- 0.2 # initial allele frequency s <- .1 # selection advantage (fitness of A is 1+s, a is 1) drift <- sel <- numeric(gens + 1) drift[1] <- p0 sel[1] <- p0 for (g in 1:gens) { # neutral drift drift[g + 1] <- rbinom(1, N, drift[g]) / N # selection then drift (haploid fitness model) p_after_sel <- (1 + s) * sel[g] / ((1 + s) * sel[g] + (1 - sel[g])) sel[g + 1] <- rbinom(1, N, p_after_sel) / N } aĆ” matplot( cbind(0:gens, 0:gens), cbind(drift, sel), type = "l", lty = 1, lwd = 4, xlab = "Generation", ylab = "Allele A frequency", col = c("grey50", "firebrick"), main = "Neutral drift vs. positive selection" ) abline(h = c(0, 1), lty = 2, col = "gray70") legend("topright", c("drift", "selected"), col = c("grey50", "firebrick"), lwd = 2, bty = "n") ``` We will see later how this can be adapte to represent change in frequency of cultural traits under different cultrural transmission regimes