Phylogenetic Regression - Brownian Motion, OU and Pagel Lambda
Summary
Concept note (no raw source). Species are not independent: shared ancestry induces correlation. Phylogenetic generalised least squares (PGLS) models with where is built from the tree: Brownian motion (BM) gives = shared root-to-ancestor branch length; Pagel’s scales off-diagonals; Ornstein-Uhlenbeck (OU) gives , a Matern-1/2 Gaussian process over patristic distance. Used in PyMC example E23 (Primates301).
Overview
Example list: https://redam94.github.io/pymc-challenges/examples.html, E23 (covariance from shared branch length, BM / Pagel’s / OU-as-GP regression, the OU ridge and a reparameterisation, conditional LOO from the precision matrix, whitening). Connects to Gaussian-process thinking in Spatial Fields - Gaussian Random Fields, Kriging and Field-Level Inference and Gaussian Process Regression.
Main Content
Brownian-motion covariance on a tree (Felsenstein 1985)
Trait evolves along branches as BM with rate . For tips , , = length of the shared path from the root to the most recent common ancestor of and ; = root-to-tip height. Equivalent to independent contrasts.
Pagel's (Pagel 1999)
for : is BM (full phylogenetic signal), is a star phylogeny (independent species). Off-diagonals are multiplied by ; the diagonal is unchanged.
Ornstein-Uhlenbeck on a tree (Hansen 1997; Martins & Hansen 1997)
with selection strength . With a stationary root, with the patristic distance (tree distance between tips) — an exponential (Matern-1/2) covariance. recovers BM. Phylogenetic half-life .
PGLS estimator
For , : , (GLS). Whitening: with , regress on by OLS.
The OU ridge: and trade off (large with large gives nearly the same covariance as small with small over the tree’s depth), producing a ridge in the posterior. Reparameterise by stationary variance and phylogenetic half-life (or correlation length) to decorrelate (as in E23).
Conditional (leave-one-out) predictive from the precision matrix
For with : (Sundararajan & Keerthi 2001; Vehtari et al. 2016). This gives exact conditional LOO for phylogenetic GP models without refitting, as long as hyperparameters are held fixed (conditional, not marginal, LOO).
Examples
Toy tree, Pagel lambda, GLS intercept, and LOO identity
Tree with root-to-tip height 2 gives . With and intercept-only : GLS mean under BM ; under equals the sample mean . Conditional LOO for species C: precision formula gives mean , variance , identical to direct conditioning (checked).
import numpy as np
C = np.array([[2, 1, 0, 0], [1, 2, 0, 0], [0, 0, 2, .5], [0, 0, .5, 2]], float)
def pagel(C, lam): M = C*lam; np.fill_diagonal(M, np.diag(C)); return M
y = np.array([1.0, 1.2, -0.3, 0.1]); X = np.ones((4, 1))
def gls(V): Vi = np.linalg.inv(V); return np.linalg.solve(X.T@Vi@X, X.T@Vi@y)
print(gls(C), gls(pagel(C, 0.0))) # 0.445, 0.5
Q = np.linalg.inv(C); i = 2; idx = [0, 1, 3]
print(y[i] - (Q@y)[i]/Q[i, i], 1/Q[i, i]) # conditional LOO mean and variance (mu = 0)PyMC sketch (untested), phylogenetic regression with Pagel’s or OU:
import pymc as pm, pytensor.tensor as pt
# C: root-to-MRCA shared length matrix; D: patristic distance matrix; scale so max height = 1
with pm.Model():
beta = pm.Normal("beta", 0, 1, shape=X.shape[1]); sigma = pm.HalfNormal("sigma", 1)
lam = pm.Beta("lam", 2, 2)
V = lam * C + (1 - lam) * pt.diag(pt.diag(C)) # Pagel lambda
# OU alternative: s2_stat = pm.HalfNormal("s2_stat", 1); ell = pm.LogNormal("ell", 0, 1); V = s2_stat/sigma**2 * pt.exp(-D/ell)
pm.MvNormal("y", mu=X @ beta, cov=sigma**2 * V, observed=y)Practical notes: cache the Cholesky of for large trees ( is fine; Ho & Ane 2014 give algorithms for BM on trees); standardise branch lengths; with missing trait values, condition via the same MvNormal marginalisation.
Marketing analogue: any hierarchy where entities share ancestry (brands in a portfolio, product taxonomy, store trees) can use a tree-induced covariance as a structured prior instead of exchangeable partial pooling (Hierarchical Models). Analogy only.
Connections
Hierarchical Models (exchangeable pooling is the star-tree special case), Joint Priors and Covariance Matrices.
See Also
Spatial Fields - Gaussian Random Fields, Kriging and Field-Level Inference