The aim of this part of the practical is to understand the output of the Bayesian phylogenetics/population genetics software BEAST. The output can be read in by standard software such as R, but BEAST has its own bespoke graphical interface called Tracer that we will explore.
Tracer. To visualize the output of the BEAST analysis, we will use Tracer. To launch it, in the docker session type tracer &
From the File menu, select Import Trace File, navigate to your working folder (/home) and select beast.mcmc1.log. Repeat to read in beast.mcmc2.log. Notice that the two files are listed in the top left of the screen, and below that is a Combined output of the two runs.
Assessing MCMC mixing and convergence
Click on clock.rate in the list of parameters on the left side bar of tracer. Select the Trace panel
Sometimes the trace is likened to a hairy caterpillar. What it shows is the way that the parameter clock.rate was sampled (i.e. simulated) from the posterior distribution by the MCMC over the iterations (labelled State on the x-axis).
You can see that the MCMC explores the posterior distribution by taking a random walk through the parameter values. This causes the evident auto-correlation in parameter values from iteration to iteration.
The first million iterations are greyed out. This phase of the run is called the burn-in before which the MCMC has reliably converged on the posterior distribution from its initial parameter values. Identifying the length of the burn-in is an inexact science, and we just used the BEAST default of one million iterations.
Following the burn-in, the hairy caterpillar should look fairly flat with relatively modest auto-correlation. If the caterpillar is obviously skewiff or the auto-correlation shows a long lag (evident as waves) this means that the MCMC is not mixing well, i.e. the random walk is not efficiently exploring the parameter values. A poorly-mixing MCMC needs running for longer, or the proposals used in the random walk need optimizing.
A useful heuristic for how well the MCMC is mixing is the ESS (effective sample size), shown in the left side bar for each parameter. The ESS, which is calculated for all iterations after the burn-in, takes account of the auto-correlation to calculate the approximate number of independent samples from the posterior distribution. An ESS below 100 suggests serious problems with the MCMC. Every parameter listed in the left side bar needs an adequate ESS.
The next step is to evaluate convergence of the MCMC. This was the reason for running multiple chains. In the top left panel labelled Trace Files, click first on beast.mcmc1.log and then hold Ctrl and click beast.mcmc2.log. As you Ctrl-click the second run, you should see its trace super-imposed on top of the trace of the first run. If the two runs have both converged, they should lie on top of each other. You can improve the graph by dragging the right frame of the Tracer window to widen the window until the Colour by drop-down list is visible. Select Colour by: Trace File. This will make the second trace purple. The two traces should both be well-mixed and should not show systematic differences such as a different mean value. Failure to converge is often accompanied by bad mixing, which will make the two traces clearly non-overlapping during some periods of the MCMC.
If you are satisfied that for every parameter the burn-in is long enough, the ESS is large enough and the MCMC shows good mixing and convergence, it is time to move on.
Interpreting the Bayesian posterior distribution
The molecular clock rate is a fundamental quantity for the interpretation of phylogenies because it provides the real-time substitution rate. Only with this information is it possible to convert phylogenetics time units or coalescent time units to calendar time. Previously we estimated the clock rate using TempEst. Now we will use BEAST to estimate this parameter.Click the Combined run from the Trace Files list in the top left corner, select clock.rate from the left side bar and choose the Marginal Prob Distribution panel on the right.
This shows you the posterior distribution of the clock rate approximated by the MCMC: it is essentially a histogram (technically, Tracer shows a smoothed kernel density estimate) of the parameter values sampled by the MCMC runs that you visualized in the trace plots.
The posterior distribution is a Bayesian statement about the probable values of the parameter. It takes into account the prior distribution you specified in BEAUti and the observed data as interpreted through the evolutionary model you specified in BEAUti.
How do you use the posterior distribution?
Point estimates. If you want to quote a single number to represent your estimate of the parameter, you can summarize the posterior by taking some form of average, such as the:
- Posterior mean. This represents the expected value of the parameter, averaging over the uncertainty in the posterior.
- Posterior median. There is 50% posterior probability that the true parameter lies below this value and 50% that it lies above it. Unlike the mean, it has the desirable property that the median of any transformation (e.g. logarithm) of the parameter equals the transformation of the median. This property is known as invariance to transformation and is shared with maximum likelihood estimates.
- Posterior mode. This is the value with the highest posterior density, so in a sense represents one's 'best guess'.
To get Tracer to provide the point estimate of your choosing, click on the Estimates panel. I obtained a posterior mean of 7.6×10-4. Do not blithely copy out 7.6E-4, because this is not scientific notation. Do not copy out 7.6413×10-4 unless (a) you are confident that the MCMC provides you with 5 significant figures of precision and (b) this level of precision is needed. BEAST helpfully provides a standard error of the mean. I got 3.6×10-6 which indicates that the true posterior mean, after accounting for the limited number of iterations of the MCMC, lies somewhere between the sample mean plus and minus two standard errors, i.e. 7.6413×10-4 ± 2×3.6×10-6 = (7.569×10-4, 7.713×10-4). This indicates that only one or two significant figures are appropriate. To obtain greater precision combine more chains or run each chain for longer. As a guide, the precision increases only with the square root of the number of iterations, so 100 times as many iterations are needed for 10 times the precision.
I obtained a posterior median of 7.6×10-4 as well. For symmetrical distributions, the mean and median will match, as here. For some reason, Tracer could not provide the posterior mode but it would probably have been similar.
Credibility intervals. The point estimate does not convey the statistical uncertainty associated with your inference. (This is different to the uncertainty represented by the standard error of the mean.) Common statistics used to summarize the uncertainty in the posterior distribution include the:
- 95% highest posterior density (HPD) interval. This is the narrowest interval within which 95% of the posterior density lies.
- 95% equal-tailed interval. This is the interval defined by the 2.5% and 97.5% percentiles. There is 2.5% probability the true parameter value lies below the interval and 2.5% probability it lies above it. Like the median, this interval is invariant to transformations of the parameter.
Unlike the semantic contortions of classical confidence intervals, a Bayesian can say "I believe there is a 95% probability that the clock rate is between 5.3×10-4 and 9.9×10-4."
This is a respectably narrow credibility interval, in the sense that there is only around a two-fold difference between the upper and lower bound.
- How do BEAST's estimates of the clock rate compare to TempEst's?
The age of the South American Zika virus outbreak
Now you're equipped to interpret the other evolutionary parameters. While you could manually take the clock rate and apply it to one of your previously estimated phylogenies to try to date the emergence of the South American outbreak, this is unnecessary because BEAST co-estimates the phylogeny along with the evolutionary parameters and, because we set it up in BEAUti, it reports the age of the most recent common ancestor (MRCA) of the South American sequences in tmrca(crown) and the age of the MRCA of the South American sequences and their next most closely related non-South American sequence in tmrca(stem). It is important to estimate both quantities because, even if the South American outbreak is monophyletic, these MRCAs can only provide bounds on (i.e. book-end) the date the outbreak began. Note that because we provided the sampling dates of the tips in years, the MRCA date estimates are also in years.- Can you calculate the credibility interval within which there is at least a 95% posterior probability that the true date of the origin of the South American outbreak began?
How rapidly did the Asian/South American Zika virus pandemic spread?
The exponential.growthRate parameter is the rate of population increase (or decrease, if negative) per year. What does the posterior distribution look like? How quickly did the outbreak spread? Do you obtain a different rate if you analyse the South American sequences alone?Advanced users might want to explore BEAUti for other methods of estimating population size changes in the Asian/South American Zika genomes or the South American genomes alone. What does the non-parametric Bayesian Skyline method infer?
Bayesian inference of the phylogeny
So far we have seen how BEAST estimates evolutionary parameters and tree statistics in a Bayesian fashion, but we have not seen how it estimates the phylogeny, also known as a genealogy in a population genetics context. A major difference between the way PhyML and BEAST estimate phylogenies is that the former estimates an unrooted tree in which the branch lengths are in phylogenetic time units (i.e. expected numbers of substitutions per site). In contrast, BEAST is able, when provided with a clock rate specified through the prior or estimated from informative data, to estimate a rooted tree in which the branch lengths are in calendar time. This rooted tree is constrained so that the tips must occur at the specified sampling times, whereas the unrooted tree estimated by PhyML is unconstrained.Another major difference is that PhyML estimates a point estimate (the maximum likelihood tree) whereas BEAST samples trees from the posterior distribution. Therefore it is necessary to summarize this posterior distribution in some way to provide a point estimate. A consensus tree can be constructed which incorporates nodes that have high posterior probability, as evidenced by their appearance in the majority of sampled trees. The branch lengths might be specified, for example, by the posterior median of each branch taken as an average over the sampled trees in which it appears.
To build a maximum clade credibility (MCC) tree in BEAST:
- Launch TreeAnnotator (type 'treeannotator &' at the command line)
- Set the Burnin to 1000 samples
- Set the Input Tree File to beast.mcmc1.trees
- Select a name for the Output File, e.g. beast.consensus.tree
- Click Run
Hackathon ideas
- There are now over 600 whole or near-whole Zika virus genomes. Can you apply what you've learned about reference-based mapping earlier to extend your phylogenetic analysis to leverage the information containined in hundreds of genomes?
- Can you apply what you've learned to understand the early dynamics of other outbreaks such as Foot and Mouth, SARS, Ebola and Coronavirus?











