Rates, continuous time, and transition probabilities
The Jukes-Cantor (JC) model: Every change is equally likely
But in the yeast SSA3 gene, observed transitions outnumbered transversions about 3 to 1 (each transition > 6 times as fast as each transversion)
And when we simulated transition-biased evolution, the JC distance underestimated the true distance
A model that ignores how sequences really evolve gives biased answers
Two rates for the two kinds of change:
| A | C | G | T | |
|---|---|---|---|---|
| A | — | \(\beta\) | \(\alpha\) | \(\beta\) |
| C | \(\beta\) | — | \(\beta\) | \(\alpha\) |
| G | \(\alpha\) | \(\beta\) | — | \(\beta\) |
| T | \(\beta\) | \(\alpha\) | \(\beta\) | — |
\(\kappa = \alpha / \beta\): How many times faster each transition is than each transversion
\(\kappa = 1\) is the JC model
\(S\) = proportion of sites that differ by a transition
\(V\) = proportion of sites that differ by a transversion
\[ d = -\frac{1}{2}\ln\left(1 - 2S - V\right) - \frac{1}{4}\ln\left(1 - 2V\right) \]
| Yeast SSA3 | JC | K80 | Estimated \(\kappa\) |
|---|---|---|---|
| Whole gene | 0.182 | 0.187 | 6.2 |
| 3rd codon positions | 0.570 | 0.655 | 9.7 |
The correction matters most where sequences have diverged the most
Last time, we chopped time into tiny steps, each with a small chance of substitution
As the steps get smaller, we approach a continuous-time Markov chain
Instead of a probability per step, we describe the model by rates: How many changes we expect per unit of time
Question: If a site changes at rate \(\lambda\), how long until it changes?
Average wait \(= 1 / \text{rate}\)
So to simulate, we just repeat:
Stationary distribution
A site reaches equilibrium at \(\pi\), not \(\frac{1}{4}\) each
Saturation
Two random draws from \(\pi\) match with probability \(\sum_i \pi_i^2\)
With 40% C and G: sequences saturate at \(p \approx 0.66\), not 0.75
The table of rates, with minus the total rate of leaving on the diagonal:
\[ Q_{\text{K80}, \kappa = 8} = \begin{bmatrix} -1 & 0.1 & 0.8 & 0.1 \\ 0.1 & -1 & 0.1 & 0.8 \\ 0.8 & 0.1 & -1 & 0.1 \\ 0.1 & 0.8 & 0.1 & -1 \end{bmatrix} \]
A, C, G, TThe probability that a site that starts as base \(i\) is base \(j\) after time \(t\):
\[ P(t) = e^{Qt} \]
scipy.linalg.expm(Q * t)K80 (\(\kappa = 8\)), \(t = 0.5\):
| From \ To | A | C | G | T |
|---|---|---|---|---|
| A | 0.658 | 0.045 | 0.251 | 0.045 |
| C | 0.045 | 0.658 | 0.045 | 0.251 |
| G | 0.251 | 0.045 | 0.658 | 0.045 |
| T | 0.045 | 0.251 | 0.045 | 0.658 |
| Model | Rates | Base frequencies | Free parameters |
|---|---|---|---|
| JC691 | All equal | Equal | 0 |
| K802 | Transitions vs. transversions (\(\kappa\)) | Equal | 1 |
| F813 | All equal | Unequal (\(\pi\)) | 3 |
| HKY854 | \(\kappa\) | Unequal (\(\pi\)) | 4 |
| GTR5 | Every pair its own rate | Unequal (\(\pi\)) | 8 |
Each model is a rate matrix \(Q\), which enables us to get \(P(t) = e^{Qt}\)
For two aligned sequences, product over sites (base \(x\) in one sequence, base \(y\) in the other):
\[ L(t) = \prod_{\text{sites}} \pi_x P_{xy}(t) \]
For our computer’s sake, we turn the product into a sum of logs:
\[ \ln L(t) = \sum_{\text{sites}} \Big[\ln(\pi_x) + \ln\big(P_{xy}(t)\big)\Big] \]
3rd codon positions:
| Model | Best \(t\) | Log-likelihood |
|---|---|---|
| JC | 0.570 | −1563.6 |
| K80 (\(\kappa = 9.66\)) | 0.655 | −1473.8 |
The \(t\) that maximizes the likelihood under each model is that model’s distance formula!
A model with an extra parameter always fits at least as well; why?
So we need to ask: Is the improvement worth the extra parameter?
K80 vs. JC for the yeast gene: About 90 log-likelihood units better, for 1 extra parameter
count_transitions_transversions and k80_distance: Fix last week’s distance biassimulate_site: Simulate evolution in continuous timeget_rate_matrix and get_transition_probabilities: Build \(Q\) and \(P(t)\) with NumPy and SciPylog_likelihood_pair: Compare JC and K80 on the yeast geneWatch for
Your simulation and \(P(t)\) are two completely different calculations. Do they agree?
I drafted and iterated on these slides in collaboration with Anthropic’s Claude (Opus 5.5 model).