The "Likelihood incorrectly calculated" message

What does “Likelihood incorrectly calculated” mean?

BEAST runs MCMC efficiently by caching some to the calculations from the previous state. For example, if the birth-rate of the Yule prior is proposed to be changed, only the Yule prior and prior on the birth rate will change. A change of birth-rate does not affect any of the calculations of the tree likelihoods, so these do not need to be recalculated. Though this makes the MCMC much more efficient, in practice caching is a source of errors. To keep developers honest, BEAST checks every 10.000 samples whether the posterior calculation obtained while caching equals the posterior. If these two posteriors do not agree (up to a small error due to machine precision) the “Likelihood incorrectly calculated” message is produced. When errors are very small (that is, if most of the significant digits agree) this may still not be problematic. But after 100 such messages BEAST stops, since this is an indication there is somethings substantially wrong.

Pro tip: In fact, if the -Dbeast.debug=true directive is passed to java, BEAST will do this check every 3rd sample for the first 6.000 samples. This is useful for developers that want to diagnose this problem quickly. With this flag, BEAST will stop after the first time this test fails.

What if there is a large positive posterior?

If the error message shows that the posterior is a large positive number the problem may be due to numerical instability. (Note that positive posteriors are fine in theory, since the reported posterior is actually the log of the posterior for which priors are not normalised, but when this error occurs the posterior is probably outside the range where it can be calculated in a stable manner.) What may have happened is that some of the parameters (maybe clock rates or birth rates) became very small or large resulting, which then due to numerical instability gives a large positive posteriors. You can check the trace log in Tracer to see which parameter escaped to an unrealistic value, and adjust the prior or the upper and lower bounds for these parameters to make sure they remain close to a value that is reasonable.

To change the bounds of a parameter, in BEAUti in the priors panel in the prior for the parameter, you can click the button with value and upper/lower bounds of the parameter. A dialog pops up where you can then change these bounds.

Parameters are not escaping – how can I solve this problem?

Another possibility is that there is a bug in the software. To find out which part of the posterior is causing the problem, BEAST prints out a report showing the various components that make up the posterior, with values of the latest state and that of the previous state (obtained when caching calculations).

The entries marked with a double asterisk are the components that are probably causing a problem. In the example above, the prior is correctly calculated, but something is wrong with the likelihood, though it is not quite clear which of the likelihoods is the cause of this.

If you see this happening, and the component is specific to a particular BEAST package, it is probably best to contact the developer of that package.