You are here

Sampling the Prior

BEAST Documentation->Tutorials->Sampling the Prior

Sampling from the prior can be done by selecting this option in the 'MCMC' panel of BEAUti when generating a BEAST XML file. To do this select the check box labelled 'Sample from prior only'. The resulting XML will be exactly the same as the normal BEAST XML except the alignment will consist entirely of characters denoting missing data. This will produce a likelihood of the data given the tree which is always '1.0' and thus BEAST will only sample from the Prior densities.


This tutorial has been left here for reference purposes and in case an existing XML file needs to be modified.

Altering a BEAST XML file so that BEAST only samples from the Prior distribution

This is an extremely useful thing to do to see how much the answer you are getting is the result of your data or simply the result of the Prior that is being used.

It is also a useful way of simulating trees under complex models: without the data, the MCMC is fast and if you sample at an adequate interval then these are independent draws from the prior.

The first thing you do is to edit the <posterior> element inside the <mcmc> element:

	<mcmc id="mcmc" chainLength="1000000" autoOptimize="true">
		<posterior id="posterior">
			<prior id="prior">
				<coalescentLikelihood idref="coalescent"/>
			</prior>
			<likelihood id="likelihood">
				<treeLikelihood idref="treeLikelihood"/>
			</likelihood>
		</posterior>

You then remove (or comment out) the reference to <treeLikelihood>:

			<!--<likelihood id="likelihood">
				<treeLikelihood idref="treeLikelihood"/>
			</likelihood> -->

The denotes a comment in XML.

Additionally, you should comment out bits where the tree likelihood is logged to the screen or a file:

		<log id="screenLog" logEvery="10000">
			<column label="Posterior" dp="4" width="12">
				<posterior idref="posterior"/>
			</column>
			<column label="Root Height" sf="6" width="12">
				<parameter idref="treeModel.rootHeight"/>
			</column>
			<!--
			<column label="L(tree)" dp="4" width="12">
				<treeLikelihood idref="treeLikelihood"/>
			</column>
			-->
			<column label="L(coalecent)" dp="4" width="12">
				<coalescentLikelihood idref="coalescent"/>
			</column>
		</log>
		<log id="fileLog" logEvery="1000" fileName="test.log">
			<posterior idref="posterior"/>
			<parameter idref="clock.rate"/>
			<parameter idref="constant.popSize"/>
			<parameter idref="hky.kappa"/>
			<parameter idref="treeModel.rootHeight"/>
			<!-- <treeLikelihood idref="treeLikelihood"/> -->
			<coalescentLikelihood idref="coalescent"/>
		</log>

You will also need to comment out certain operators that operate on parameters that are used to calculate the likelihood of the data: HKY model's kappa parameter GTR model's transition rates parameter Gamma distribution's shape parameter Invariant site model's pInv parameter.


Return to Tutorials