Documentation
About the package
This package is primarily based on the quasistatic version of the “model switch integration method” laid out in a paper by Nicolas Lartillot and Hervé Phillipe titled Computing Bayes Factors Using Thermodynamic Integration
The modification we have made to their method is changing the value of beta at every step of the MCMC chain rather than at set intervals. Beta is therefore changed very slowly, so as to not cause issues with equilibration.
Summary of the method
The main idea of this method is to progressively change the target density from being the posterior of one model to the posterior of another model, which allows estimation of the Bayes factor.
This is accomplished by setting the posterior density to the product of the two model posteriors, with one raised to the power of the parameter beta and the other raised to 1 - beta.
Regularly across the chain, a value called U in the Nicolas Lartillot and Hervé Phillipe paper is calculated, which is later used in estimating the Bayes factor.
Please read the above paper to obtain a more thorough understanding of this method.
Installation
Please refer to the instructions for installation
Basics of Usage
This package can be used to calculate the Bayes factor of one model over another. It can be used in certain cases where path sampling fails, particularly where sampling from the prior is impractical.
One use of this is for structured trees (eg. using MultiTypeTree) which becomes challenging when there are more than just a few demes.
It is also worth checking out the tutorials.
General overview of how this package can be used:
- Install the ModelComparison package
- Setup a BEAST XML file which specifies your analysis (see tutorials and below documentation, as well as examples in the package directory)
- Equilibrate the run (run an initial chain until equilibrated) (more detail in tutorials)
- Modify the betaControlMode value in the XML file (telling ModelComparison to progressively switch between your two models)
- Resume the run using the modified XML file
- Run the command line tool (built-in) to estimate the Bayes factor using the log file
Overview of the package
This package uses:
- a customised version of BEAST’s MCMC chain which allows the beta value to be changed incrementally and evenly throughout the course of the run.
- a customised distribution which allows you to switch between two posteriors depending on the value of beta
- a logger which records the beta and U values as often as you wish
- a tool which uses the recorded beta and U values to estimate the Bayes factor
BEAST Objects
beast.math.distributions.ModelComparisonDistribution
This BEAST object is a Distribution, and it does the work of calculating the posterior using the beta value and the two provided Distribution inputs.Options/Inputs
name:betaParameterUsage example
<distribution
id="posterior"
spec="beast.math.distributions.ModelComparisonDistribution"
betaParameter="@myBetaParameter">
<distribution id="posterior_for_first_model"/>
<distribution id="posterior_for_second_model"/>
</distribution>
beast.core.ModelComparisonMCMC
This extends BEAST'S usual MCMC chain code to allow for the values of beta to be changed very slowly at every step of the chain.Options/Inputs
name:betaParameterstatickeep beta the same throughout the run
onewayslowly change beta from either 0 to 1 or 1 to 0 throughout the run
bothwaysslowly change beta in one direction, then back again to the starting value throughout the run
Note: Before using Model Comparison to control the value of beta, you must first equilibrate your run using beta set to either 0 or 1
Usage example
Instead of using this:<run chainLength="20000000" id="mcmc"
spec="beast.core.MCMC">
</run>
<run chainLength="20000000" id="mcmc"
spec="beast.core.ModelComparisonMCMC"
betaParameter="@myBetaParameter"
betaControlMode="static">
</run>
beast.core.util.ModelComparisonLogger
This allows for logging the values of beta and U (as defined in the Lartillot and Phillipe paper).Options/Inputs
name:posteriorDistributionUsage example
Add the following to any logger (eg. the screenlog or tracelog logger:<log spec="util.ModelComparisonLogger" posteriorDistribution="@posterior"/>
<!-- @posterior here means that our posterior object has the id "posterior" -->
<logger fileName="$(filebase)_beta_U.log" id="betaAndUValueLogger" logEvery="500">
<log spec="util.ModelComparisonLogger" posteriorDistribution="@posterior"/>
<!-- Here we have used $(filebase) in the filename - BEAST will replace that part with the filename of your XML file (without the .xml extension) -->
</logger>