Evolution is a stochastic process and the statistical framework for evolution arose through the modern synthesis.
Basic tenets of the modern synthesis:
The units of evolution are populations.
Genetic and phenotypic variability in eukaryotes is brought about by genetic recombination resulting from sexual reproduction and random mutations.
Natural selection, particularly directional selection, shapes the course of phenotypic evolution.
Speciation can be defined as the stage in evolutionary process at which members of the same species can no longer interbreed.
New species evolve from pre-existing species by slow processes and maintain at each stage their specific adaptations.
Macroevolution is the gradual step-by-step process that is extrapolated from microevolutionary processes.
Probability and evolution
Notably one botanist, G. Ledyard Stebbins (1906–2000), was around for the modern synthesis, but these core tenets were developed primarily by zoologists and paleontologists.
Stebbins was a key figure in the development of the modern synthesis for plants, and he was a strong advocate for the importance of polyploidy in plant evolution.
Do we notice any of the tenets that might be problematic for plants?
Probability and evolution
Probabilities sneak in fast with genetics. Think about Hardy-Weinberg Equilibrium.
Independent discovery of the “sum of probabilities” equation by G. H. Hardy (1877–1947) and Wilhelm Weinberg (1862–1937) based on Mendel’s laws of inheritance.
Probability and evolution
For a site with two alleles, \(A_1\) and \(A_2\), with frequencies \(p\) and \(q = 1 - p\), the expected genotype frequencies are: \[A_1A_1: p^2, \quad A_1A_2: 2pq, \quad A_2A_2: q^2\]
and \[p^2 + 2pq + q^2 = 1\]
Probability and evolution
A toy example:
Probability and evolution
The genotype probability calculations are possible because of some basic rules of probability. This includes independence and the product of mutually exclusive events. There is also a model that underlies HWE expectations.
To approach deviations from HWE expectations, the modern synthesis, and more complex extensions, we need some foundation in probability theory.
Probability building blocks
Probability and likelihood
Rules of probability, examples with a 10-side die:
The probability of any single outcome: \(Pr(X = x) = \frac{1}{10}\) for \(x = 1, 2, \dots, 10\).
The probability of an event (e.g., rolling an even number): \(Pr(X \text{ is even}) = \frac{5}{10} = \frac{1}{2}\).
Probability and likelihood
Rules of probability, examples with a 10-side die:
The probability of any single outcome: \(Pr(X = x) = \frac{1}{10}\) for \(x = 1, 2, \dots, 10\).
The probability of an event (e.g., rolling an even number): \(Pr(X \text{ is even}) = \frac{5}{10} = \frac{1}{2}\).
That even number could be rewritten as a bunch of “or” statements: \[Pr(X \text{ is even}) = Pr(X=2 \text{ or } X=4 \text{ or } X=6 \text{ or } X=8 \text{ or } X=10)\]\[\quad = \frac{1}{10} + \frac{1}{10} + \frac{1}{10} + \frac{1}{10} + \frac{1}{10}\]\[\quad = \frac{5}{10}\]\[\quad = \frac{1}{2}\]
Probability and likelihood
What about 2 and 4 and 6 and 8 and 10 as successive rolls independent rolls?
The probability of rolling 2 and 4 and 6 and 8 and 10 on successive independent rolls is: \(Pr(X_1=2 \text{ and } X_2=4 \text{ and } X_3=6 \text{ and } X_4=8 \text{ and } X_5=10) = \frac{1}{10} \cdot \frac{1}{10} \cdot \frac{1}{10} \cdot \frac{1}{10} \cdot \frac{1}{10} = \frac{1}{100000}\)
Probability and likelihood
All probabilities have models underlying them. The probability of rolling a 2 on a 10-sided die is \(Pr(X=2) = \frac{1}{10}\) because the die is fair and has 10 sides.
We could write this as: \[Pr(X=2 \mid \text{10-sided die}) = \frac{1}{10}\]
A probability predicts the outcome of a random event given a model. A likelihood evaluates the plausibility of a model given an observed outcome - written as \(L(\theta \mid X)\).
Probability and likelihood
Likelihood - your relative level of suprise of an observation given a model.
Changing the model to a four-sided die increases the likelihood of observing \(X\) from \(\frac{1}{10000}\) to \(\frac{1}{256}\). It is likely that a four-sided die was used to generate the data.
Likelihood provide a way to estimate model parameters
A likelihood treats the data as fixed and \(\theta\) as the variable:
\[\mathcal{L}(\theta \mid X = k) = P(X = k \mid \theta)\]
Same formula — different question being asked.
# Observed: k = 3 mutations on a branch. Model: X ~ Poisson(λ).lambda <-seq(0.01, 10, length.out =500) # range of possible λ valueslik <-dpois(3, lambda = lambda) # likelihood at each λplot(lambda, lik, type ="l", lwd =2, col ="#0A2342",xlab =expression(lambda),ylab =expression(L(lambda ~"|"~ k ==3)),main ="Likelihood of \u03bb given 3 observed mutations")abline(v =3, lty =2, col ="#F15025", lwd =2) # mark the MLElegend("topright", legend =expression(hat(lambda)[MLE] ==3),lty =2, col ="#F15025", bty ="n")
The MLE \(\hat\lambda = k = 3\) — the observed count is the best estimate of the Poisson rate.
Where do probabilities come from?
Random variables & expectations
What is a random variable?
Random Variables & Expectations
A random variable (RV) is a variable whose possible values are numerical outcomes of a random phenomenon. 1. discrete RVs take on a countable number of distinct values (e.g., 0, 1, 2, …). 2. continuous RVs take on an uncountable number of values, typically intervals of real numbers (e.g., \([0,1]\)).
The behavior of discrete RVs is described by a probability mass function (PMF), which gives the probability of each possible value.
\(Pr(X = x) = f(x)\)
The behavior of continuous RVs is described by a probability density function (PDF), which gives probabilities over intervals of values. Any single value has probability 0, but the area under the curve over an interval gives the probability of falling in that interval.
\(Pr( a \le X \le b) = \int_a^b f(x)\,dx\)
Both discrete and continuous RVs have cumulative distribution functions (CDFs), which give the probability of falling below a given value:
\(F(x) = Pr(X \le x)\)
Expectation and variance
It is often useful to summarize a random variable with a single number. The mean of a distribution is also the expectation or expected value of a random variable \(X\):
For discrete RVs:
\[\bar{x} = \sum_x x\,Pr(X = x)\]
and the variance (or expected squared deviation from the mean) is given by:
Variance measures the scatter of a variable around its mean. The standard deviation is the square root of the variance and often used when showing data since it is in the same units as the variable itself.
Expectation and variance
The notation of expectations is sometimes encountered in the wild.
Mean:
\[\mathbb{E}[X] = \bar{x}\]
Variance can apply linearity to achieve a shortcut:
The mean and variance are derived from a moment generating function as the first and second moments of a distribution. Moment generating functions are beyond our scope, but you might encounter the term “moments” in the literature.
In practice though, we are not evaluating integrals analytically, but rather using numerical methods to approximate the mean and variance of continuous distributions. Approximation means sum!
Sneaking in the \(1/(n-1)\) term is a correction for the fact that we are estimating the population variance from a sample. This is to ensure our estimator is unbiased. if the difference between \(n\) and \(n-1\) ever matters to you, then you are probably up to no good anyway.
Random Variables & Expectations Summary
A random variable\(X\) maps possible outcomes from a model to real numbers.
Discrete RVs: probability mass function (PMF) \(Pr(X = k) \ge 0\), \(\sum_k Pr(X=k) = 1\).
Continuous RVs: probability density function (PDF) \(f(x) \ge 0\), \(\int_{-\infty}^{\infty} f(x)\,dx = 1\).
Expectation: \(\mathbb{E}[X] = \sum_k k\,P(X=k)\) or \(\int x\,f(x)\,dx\).
Biological reading: \(n\) = gene copies sampled from a population, \(k\) = copies that are allele \(A_1\), \(p\) = allele frequency. One round of Wright–Fisher drift is one binomial draw.
Binomial: E[X] and Var(X)
Indicator variable trick. Let \(X_i = 1\) if trial \(i\) succeeds, 0 otherwise. Then:
Since trials are independent, \(\mathrm{Var}(X_i) = \mathbb{E}[X_i^2] - p^2 = p - p^2 = p(1-p)\), so:
\[\boxed{\mathrm{Var}(X) = np(1-p)}\]
Variance is maximised at \(p = 0.5\) and collapses to zero when \(p \in \{0, 1\}\).
Binomial in R
par(mfrow =c(1, 3), mar =c(4, 4, 3, 1)) # 3 panels side by sidens <-c(10, 20, 50) # number of trials to comparep <-0.3# success probabilityfor (n in ns) { k <-0:n # all possible count outcomesbarplot(dbinom(k, size = n, prob = p), names.arg = k,main =paste0("Binom(n=", n, ", p=0.3)"),xlab ="k", ylab ="P(X = k)",col ="#2CA58D", border =NA, cex.names =0.6)}
Increasing \(n\) concentrates the distribution around \(\mathbb{E}[X] = np\); shape approaches Normal for large \(n\) (Central Limit Theorem).
Poisson: definition
\(X \sim \text{Poisson}(\lambda)\) — count of independent events in a fixed interval when events arrive at constant rate \(\lambda\).
Biological reading: \(\lambda = \mu t\) where \(\mu\) is the per-site substitution rate and \(t\) is branch length. The number of mutations on a branch \(\sim \text{Poisson}(\mu t)\).
Poisson: E[X] and Var(X)
\[\mathbb{E}[X] = \sum_{k=0}^{\infty} k \cdot \frac{e^{-\lambda}\lambda^k}{k!} = e^{-\lambda} \sum_{k=1}^{\infty} \frac{\lambda^k}{(k-1)!}\]
Memoryless: \(P(X > s + t \mid X > s) = P(X > t)\) — the process has no memory of how long it has waited.
Biological reading: time until coalescence of two lineages in a population of size \(N_e\) is \(\text{Exponential}(1/N_e)\) (in units of generations). Waiting time to a mutation at rate \(\mu\) is \(\text{Exponential}(\mu)\).
Applying the same method to \(\mathbb{E}[X^2]\) (with \(u = x^2\)) gives \(\mathbb{E}[X^2] = 2/\lambda^2\), so:
\[\boxed{\mathrm{Var}(X) = \frac{1}{\lambda^2}}\]
Exponential in R
par(mfrow =c(1, 3), mar =c(4, 4, 3, 1)) # 3 panels side by siderates <-c(0.5, 1, 3) # three rate values to comparex <-seq(0, 8, length.out =400) # x-axis values for the density curvefor (lam in rates) {plot(x, dexp(x, rate = lam), type ="l", lwd =2, col ="#6F1A07",main =bquote(Exp(lambda == .(lam))),xlab ="x", ylab ="f(x)", ylim =c(0, 3.2))# dashed vertical line at E[X] = 1/lambdaabline(v =1/lam, lty =2, col ="#0A2342", lwd =1.5)# label the expected value in the legendlegend("topright", legend =bquote(E[X] == .(round(1/lam, 2))),lty =2, col ="#0A2342", bty ="n")}
Dashed line marks \(\mathbb{E}[X] = 1/\lambda\). High rate → short expected wait; low rate → long tail.
Geometric: definition
\(X \sim \text{Geometric}(p)\) — number of trials until (and including) the first success, where each trial succeeds independently with probability \(p\).
Parameter: \(p \in (0,1)\) — success probability per trial.
Discrete analogue of the Exponential; also memoryless.
Biological reading: in a haploid population of size \(N\), two lineages coalesce in any given generation with probability \(1/N\). The generation of coalescence \(\sim \text{Geometric}(1/N)\).
Geometric: E[X] and Var(X)
\[\mathbb{E}[X] = \sum_{k=1}^{\infty} k\,(1-p)^{k-1}\,p = p \cdot \frac{d}{dq}\!\left[\sum_{k=0}^{\infty} q^k\right]_{q=1-p}\]
Using the geometric series \(\sum_{k=0}^\infty q^k = \frac{1}{1-q}\) and differentiating:
\[\frac{d}{dq}\frac{1}{1-q} = \frac{1}{(1-q)^2} \implies \mathbb{E}[X] = p \cdot \frac{1}{p^2}\]
\[\boxed{\mathbb{E}[X] = \frac{1}{p}}\]
Using \(\mathbb{E}[X(X-1)]\) (same technique), \(\mathbb{E}[X^2] = (2-p)/p^2\), giving:
\[\boxed{\mathrm{Var}(X) = \frac{1-p}{p^2}}\]
Geometric in R
# R's dgeom(k, prob) counts *failures* before first success (support 0, 1, 2, …).# Add 1 to shift to the "trial of first success" convention used above.par(mfrow =c(1, 3), mar =c(4, 4, 3, 1))probs <-c(0.1, 0.3, 0.7)for (p in probs) { k <-0:40barplot(dgeom(k, prob = p), names.arg = k +1,main =bquote(Geom(p == .(p))),xlab ="k (trial of first success)", ylab ="P(X = k)",col ="#F15025", border =NA, cex.names =0.55)}
Note
dgeom(k, prob = p) in R returns \(P(X = k + 1)\) in our notation — it counts failures, not trials. Always shift by 1 when comparing to the PMF formula above.
Normal: definition
\(X \sim \mathcal{N}(\mu,\, \sigma^2)\) — the bell curve; the limiting distribution of sums of independent random variables (Central Limit Theorem).
\[f(x) = \frac{1}{\sigma\sqrt{2\pi}}\exp\!\left(-\frac{(x-\mu)^2}{2\sigma^2}\right), \quad x \in \mathbb{R}\]
\(\mathbb{E}[X] = \mu\), \(\quad\mathrm{Var}(X) = \sigma^2\) — parameters are the moments.
Symmetric around \(\mu\); 68 / 95 / 99.7% of mass within \(1/2/3\,\sigma\).
Biological reading: trait values under polygenic additive models; log-transformed allele frequencies near fixation; large-sample approximation to Binomial and Poisson.
Normal in R
par(mfrow =c(1, 3), mar =c(4, 4, 3, 1)) # 3 panels side by sidemus <-c(0, 0, 3) # mean valuessigmas <-c(1, 2, 1) # standard deviationslabels <-c("N(0,1)", "N(0,4)", "N(3,1)")x <-seq(-6, 9, length.out =400) # x-axis valuesfor (i inseq_along(labels)) { mu <- mus[i] # mean s <- sigmas[i] # standard deviationplot(x, dnorm(x, mean = mu, sd = s), type ="l", lwd =2, col ="#2CA58D",main = labels[i], xlab ="x", ylab ="f(x)", ylim =c(0, 0.45))# dashed line at the mean muabline(v = mu, lty =2, col ="#6F1A07", lwd =1.5)}
Dashed line marks \(\mu\). Changing \(\sigma\) scales the spread without shifting the centre.
Normal: polygenic traits
Many loci each contributing a small additive effect → trait values converge to Normal (CLT).
Red curve: \(\mathcal{N}(0, L)\). With 100 loci the histogram is already nearly indistinguishable from the Normal — the basis of the infinitesimal model of quantitative genetics.
Log-Normal: definition
\(X \sim \text{LogNormal}(\mu,\, \sigma^2)\) — \(X > 0\) and \(\ln X \sim \mathcal{N}(\mu, \sigma^2)\).
\[f(x) = \frac{1}{x\,\sigma\sqrt{2\pi}}\exp\!\left(-\frac{(\ln x - \mu)^2}{2\sigma^2}\right), \quad x > 0\]
Parameters: \(\mu, \sigma^2\) are the mean and variance of the log-scale.
Right-skewed; naturally bounded at zero; multiplicative processes generate it.
Biological reading: body sizes, gene expression levels, species abundances, substitution rates across sites — all tend to be log-normally distributed because they arise from multiplicative growth processes.
Log-Normal in R
par(mfrow =c(1, 3), mar =c(4, 4, 3, 1)) # 3 panels side by sidemus <-c(0, 0, 1) # log-scale meansvar_s <-c(0.25, 1, 0.5) # log-scale varianceslabels <-c("LN(0, 0.25)", "LN(0, 1)", "LN(1, 0.5)")x <-seq(0.001, 10, length.out =400) # x-axis values (must be > 0)for (i inseq_along(labels)) { mu <- mus[i] # log-scale mean s2 <- var_s[i] # log-scale varianceplot(x, dlnorm(x, meanlog = mu, sdlog =sqrt(s2)), type ="l", lwd =2,col ="#D5A021", main = labels[i], xlab ="x", ylab ="f(x)")# dashed line at E[X] = exp(mu + sigma^2/2)abline(v =exp(mu + s2/2), lty =2, col ="#0A2342", lwd =1.5)}
Dashed line marks \(\mathbb{E}[X] = e^{\mu + \sigma^2/2}\). Increasing \(\sigma^2\) pulls the mean right and increases right-skew.
Log-Normal: Ks distributions after WGD
Synonymous divergence (Ks) between duplicated gene pairs is log-normally distributed — log-transforming reveals the underlying Normal.
Special cases: \(\text{Gamma}(1, \beta) = \text{Exponential}(\beta)\); \(\text{Gamma}(k/2, 1/2) = \chi^2_k\).
Biological reading: the Gamma model of rate variation across sites is central to phylogenetics — site rates are drawn from a Gamma distribution with shape parameter \(\alpha\), which controls how much rate heterogeneity there is. Small \(\alpha\) → high variance; \(\alpha \to \infty\) → constant rates.
Gamma in R
par(mfrow =c(1, 3), mar =c(4, 4, 3, 1)) # 3 panels side by sidealphas <-c(0.5, 2, 5) # shape values to comparebetas <-c(1, 1, 1) # rate values (all 1 here)labels <-c("Gamma(0.5, 1)", "Gamma(2, 1)", "Gamma(5, 1)")x <-seq(0.001, 15, length.out =500) # x-axis values (must be > 0)for (i inseq_along(labels)) { a <- alphas[i] # shape alpha b <- betas[i] # rate betaplot(x, dgamma(x, shape = a, rate = b), type ="l", lwd =2, col ="#F15025",main = labels[i], xlab ="x", ylab ="f(x)", ylim =c(0, 1.5))# dashed line at E[X] = alpha/betaabline(v = a/b, lty =2, col ="#0A2342", lwd =1.5)}
Dashed line marks \(\mathbb{E}[X] = \alpha/\beta\). The shape parameter \(\alpha\) controls skewness: small \(\alpha\) → highly right-skewed (many slow sites, few fast); large \(\alpha\) → near-Normal.
Gamma: among-site rate variation
The \(+\Gamma\) model draws a relative substitution rate for each site from Gamma\((\alpha, \alpha)\) (mean \(= 1\)). Small \(\alpha\) creates extreme rate heterogeneity; ignoring it biases branch-length estimates.
set.seed(7)par(mfrow =c(1, 3), mar =c(4, 4, 3, 1)) # 3 panels side by sidealphas <-c(0.3, 1, 5) # three shape values to comparefor (a in alphas) {# setting rate = alpha normalises the mean to 1 (mean = shape/rate) rates <-rgamma(2000, shape = a, rate = a)hist(rates, breaks =60, col ="#F15025", border =NA, freq =FALSE,xlim =c(0, 5), main =bquote(alpha == .(a) ~"(mean = 1)"),xlab ="Relative site rate", ylab ="Density")# overlay the theoretical Gamma densitycurve(dgamma(x, shape = a, rate = a), add =TRUE, col ="#0A2342", lwd =2)# dashed line at the mean (= 1 by construction)abline(v =1, lty =2, col ="#6F1A07")}
\(\alpha = 0.3\): most sites evolve slowly, a few extremely fast (hard to model without \(+\Gamma\)). \(\alpha = 5\): rates nearly uniform. → Speciation 05 (phylogenetics theory).
Beta: definition
\(X \sim \text{Beta}(\alpha,\, \beta)\) — a flexible distribution for probabilities and proportions bounded on \([0, 1]\).
\[f(x) = \frac{x^{\alpha-1}(1-x)^{\beta-1}}{B(\alpha,\beta)}, \quad x \in [0,1]\]
where \(B(\alpha,\beta) = \Gamma(\alpha)\Gamma(\beta)/\Gamma(\alpha+\beta)\) is the beta function.
Conjugate prior for the Binomial likelihood in Bayesian inference.
Biological reading: allele frequencies, heterozygosity, admixture proportions — any quantity naturally constrained to \([0,1]\).
Beta in R
par(mfrow =c(1, 3), mar =c(4, 4, 3, 1)) # 3 panels side by sidealphas <-c(0.5, 2, 5) # alpha (shape1)betas <-c(0.5, 5, 2) # beta (shape2)labels <-c("Beta(0.5, 0.5)", "Beta(2, 5)", "Beta(5, 2)")x <-seq(0.001, 0.999, length.out =400) # x in (0,1)for (i inseq_along(labels)) { a <- alphas[i] # alpha (shape1) b <- betas[i] # beta (shape2)plot(x, dbeta(x, shape1 = a, shape2 = b), type ="l", lwd =2, col ="#6F1A07",main = labels[i], xlab ="x", ylab ="f(x)")# dashed line at E[X] = alpha/(alpha+beta)abline(v = a/(a+b), lty =2, col ="#0A2342", lwd =1.5)}
Dashed line marks \(\mathbb{E}[X] = \alpha/(\alpha+\beta)\). Beta(2,5) skews toward low allele frequencies; Beta(5,2) toward high.
Beta: allele frequency drift
Under neutral drift, the stationary distribution of allele frequencies is Beta\((\theta/2,\,\theta/2)\) where \(\theta = 4N_e\mu\). Low \(\theta\) → most sites near fixation or loss; high \(\theta\) → intermediate frequencies.
set.seed(3)par(mfrow =c(1, 3), mar =c(4, 4, 3, 1)) # 3 panels side by sidefor (theta inc(0.5, 2, 10)) {# stationary Beta distribution: both shape parameters = theta/2 freqs <-rbeta(5000, theta/2, theta/2)hist(freqs, breaks =40, col ="#6F1A07", border =NA, freq =FALSE,main =bquote(theta == .(theta)),xlab ="Allele frequency p", ylab ="Density",xlim =c(0, 1))# overlay the theoretical Beta densitycurve(dbeta(x, theta/2, theta/2), add =TRUE, col ="#0A2342", lwd =2)}
Left (\(\theta=0.5\)): most SNPs are near fixation or loss — typical of small populations. Right (\(\theta=10\)): many polymorphic sites at intermediate frequency. → Popgen 01 (genetic diversity) and Popgen 02 (population structure).
Uniform: definition
\(X \sim \text{Uniform}(a,\, b)\) — all values in \([a, b]\) are equally likely.
Maximum entropy distribution on a bounded interval — the least informative prior when only bounds are known.
Discrete analogue: \(\text{Uniform}\{1, \ldots, n\}\) with \(\mathbb{E}[X] = (n+1)/2\).
Biological reading: non-informative (flat) Bayesian priors on bounded parameters, e.g. \(\pi \sim \text{Uniform}(0,1)\) for base frequency priors in phylogenetic models; random starting values in optimisation.
Uniform in R
par(mfrow =c(1, 2), mar =c(4, 4, 3, 1)) # 2 panels side by side# Panel 1: continuous Uniform densityx <-seq(-0.1, 1.1, length.out =400)plot(x, dunif(x, min =0, max =1), type ="l", lwd =2, col ="#2CA58D",main ="Uniform(0, 1) = Beta(1,1)", xlab ="x", ylab ="f(x)", ylim =c(0, 1.5))# Panel 2: discrete Uniform by simulationset.seed(42)draws <-sample(1:6, 10000, replace =TRUE) # roll a fair 6-sided die 10,000 timesbarplot(table(draws)/10000, col ="#D5A021", border =NA,main ="Discrete Uniform{1,...,6}", xlab ="x", ylab ="Proportion")
Uniform\((0,1)\) is a special case of Beta\((1,1)\) — a flat prior that says all values in \([0,1]\) are equally plausible.
Key takeaways
Evolution is a stochastic process
A stochastic process = a random variable indexed by time.
Poisson process — events at constant rate \(\lambda\); interarrival times \(\sim \text{Exponential}(\lambda)\); counts \(\sim \text{Poisson}(\lambda t)\).
Markov chains — memoryless state change; the substitution CTMC (phylo) and drift.
Note
This is the toolbox for the rest of the course: drift (binomial sampling), mutation (Poisson), the coalescent (exponential waiting times), and substitution models (continuous-time Markov chains). → popgen deck 01; phylogenetics theory.
Review Questions
What is an RV?
What is the difference between discrete and continuous RVs?
What are the expectations of RVs?
Can you apply basic AND and OR rules of probability?
How is a likelihood different from a probability?
Can you recall the binomial, Poisson, geometric, exponential distributions and their biological uses?