vignettes/calculationUpdate.Rmd
calculationUpdate.RmdThere was an issue in OUMA and OUMVA models in OUwie versions from its origin through 2.17. This has now been fixed in OUwie versions 3.00 and up. Jeremy and Brian deeply apologize for this error. Details below:
Priscilla Lau reached out to Jeremy Beaulieu in Aug, 2025, at a
conference about an issue she and her collaborators (Bjørn Kopperud and
Sebastian Höhna) found in how OUwie calculates the
variance-covariance matrix under the OU model when there are different
parameters, as well as an error in one of the equations in the original
Beaulieu et al. (2012) paper. She followed up with an email on Sept 3,
2025; after a discussion of how best to handle this, we put a warning on
the use of models with different
in OUwie (on Sept. 6, 2025). A further email from Priscilla
and colleagues had additional details on the issues.
Brian spent some time trying to fix the code; Jeremy swooped in and actually fixed the code using the approaches from Priscilla, Bjørn, and Sebastian.
We are posting this vignette; we will soon reach out to Evolution for a correction to Beaulieu et al. (2012).
In the appendix on page 2383, when it describes the covariation under an OUMVA model, the right-most calculation in the final term is rendered as when it should be as it is correctly written in Eq. A.26. This is unrelated to the issue below but still worth noting.
For model inference the way OUwie calculated the
variance-covariance matrix under the OU model with multiple
parameters was indeed incorrect. In an Ornstein–Uhlenbeck process,
shared variance decays through time as a function of the
parameter: higher values of
cause trait values to lose memory of their shared history more rapidly,
making the optima toward which lineages are pulled more important than
their ancestral states.
The key issue is how variance decay is handled. The recursive approach of Lau et al. (in review – we will update this vignette when it becomes available) builds variance step-by-step along each branch, correctly applying decay at each stage. In contrast, Eq. 13 on page 2371 gives a closed-form expression, but does not fully account for how decay accumulates across segments when varies. As a result, it is not equivalent in the general multi- case, although the two agree when is constant (i.e., the BM1, BMS, OU1, OUM, and OUMV cases).
Adopting the corrections proposed by Priscilla Lau and colleagues, we
have updated the code in OUwie version 3.01 (released March
6, 2026) to correctly calculate the variance-covariance matrix under the
OU model with multiple
parameters. We thank Priscilla Lau, Bjørn Kopperud, and Sebastian Höhna
for their careful work in identifying this issue and proposing a
solution.
This part was written by Lau, Kopperud, and Höhna (though Beaulieu & O’Meara agree with it – we just don’t want to take credit for the discovery).
The expectation of the trait value for species is a sum over the vector , weighted by
where is the parameter for the root value, and are the state-dependent optima for regimes 1, 2, and so on. Thus, each represents the relative contribution of either the root value or the optima on the expected value at the tip. As described in Beaulieu et al. (2012), the weights are as follows
In the new (Lau et al.) derivation, the general equations are,
There are two differences in the way Beaulieu et al. (2012) construct when takes different values across epochs compared with the new derivation. First—in Beaulieu et al. (2012)’s derivation, the decay variable is outside of the summation function, and their summation function starts with epoch index . This implies that the decay always starts from the root, regardless of when each epoch ends. However, the contribution of epoch on the expected value should only begin decaying when the epoch the ends. Therefore, in the new equations, the decay variable is inside the summation function, and is dependent on the time when each epoch ends (see the sum that iterates over all epochs ).
The second factor of in Beaulieu et al. (2012)’s derivation is also different. The factor is taken from Hansen (1997). However, Hansen (1997) assumes that takes the same value in all epochs, and the factor already incorporates how the weight of each epoch-specific optimum decays after the respective epoch. Since in Beaulieu et al. (2012)’s models can take multiple values, the decay variable has to be extracted out of the factor.
Furthermore, Hansen (1997) stated that the weights should sum to one, which is the case using our derivation. The extra step where “each row entry in is divided by the sum of its row to ensure that the weights for each species sum to 1” [Beaulieu et al. (2012)] is not required when the weights sum to one.
Here, we calculate the covariance between the trait value for species and the trait value for species , i.e., As described in Beaulieu et al. (2012),
In our derivation, the general equations are
The difference lies in the first factor, which describes the exponential decay of the variance since the divergence of species and . In @Beaulieu2012’s derivation, the exponent in the first factor always calculates from the root (), which means the decay always begins at the root. In our derivation, the decay starts from the time when species and diverge ().
We use a simple character history of two species for demonstration. Epochs in black are in regime A and epochs in red are in regime B. Thus, th lineage has epochs, th lineage has epochs, while the ancestral lineage until the divergence has epoch. The time variable is understood as “time elapsed since the root of the phylogeny”. For simplification, we also set each epoch in lineage to have equal lengths ().
Therefore,
How big of a difference does this make?
The exact impact will depend on the tree, the values, and the data. In some cases it could be substantial. There is no predicted effect of whether this makes OUMVA or OUMA models seem to fit better or worse than they should otherwise.
Can I verify how this affects my analyses?
Yes, with OUwie() and similar functions we have added a
revert.old argument that defaults to FALSE. If
you set revert.old=TRUE, it will always use the old,
incorrect method for calculating the variance-covariance
matrix. You can compare results with revert.old=TRUE and
revert.old=FALSE to see how much of a difference it makes
for your specific analysis. We wanted to make sure that any problems are
transparent and reproducible.
Was hOUwie affected?
Yes, in the same way for the multiple models only, and corrected in the same way.
Can I see more details on the changes?
Yes, compare, for example, the code around line 56 of varcov.ou.R with the code around line 166 of the original calculation for trees with stochastic maps
for(regimeindex in 1:length(currentmap)){
dt <- as.numeric(currentmap[regimeindex])
regimenumber <- which(colnames(phy$mapped.edge) == names(currentmap)[regimeindex])
a <- alpha[regimenumber]
s2 <- sigma[regimenumber]
nodevar1[i] <- nodevar1[i] + a * dt
nodevar2[i] <- nodevar2[i] + s2 * exp(2 * Acur) * (exp(2 * a * dt) - 1) / (2 * a)
Acur <- Acur + a * dt
}
Ato[desc] <- Acur
for (regimeindex in 1:length(currentmap)){
regimeduration <- currentmap[regimeindex]
newtime <- oldtime+regimeduration
regimenumber <- which(colnames(phy$mapped.edge)==names(currentmap)[regimeindex])
nodevar1[i] <- nodevar1[i]+alpha[regimenumber]*(newtime-oldtime)
nodevar2[i] <- nodevar2[i]+sigma[regimenumber]*((exp(2*alpha[regimenumber]*newtime)-exp(2*alpha[regimenumber]*oldtime))/(2*alpha[regimenumber]))
oldtime <- newtime
newregime <- regimenumber
}
Some of the variables have changed names, but a key change is in how the time accumulates along the tree, with it being scaled by alpha in the new code.