Running Coalescent Analyses With coalescentMCMC

Emmanuel Paradis

Coalescent analysis is a powerful approach to investigate the demography of populations using genetic data. The coalescent is a random process describing the coalescent times of a genealogy with respect to population size and mutation rate. In the majority of cases, the genealogy of individuals within a population is unknown. So a coalescent analysis typically integrates over the likely genealogies to make inference on the dynamics of the population. This uses computer-intensive methods such as Monte Carlo simulations of Markov chains. Besides, if priors are defined on the distributions of the parameters, Bayesian inference can be done. Several methods have been proposed for such integrations, although currently there is no consensus on which method is the best, or which ones are the most appropriate in some circumstances Felsenstein (2007).

coalescentMCMC aims to provide a general framework to run coalescent analyses. In its current version, the package provides a simple MCMC algorithm based on Hastings’s ratio.

coalescentMCMC has three main groups of functions that have different roles:

  • •

    the function coalescentMCMC itself which runs the chain;

  • •

    some functions doing operations on tree which are called by the previous one to move from one tree to another;

  • •

    some functions to infer demography from genealogies under various coalescent models which are typically used to analyse the output of a chain run.

The motivating idea behind coalescentMCMC is that the user can have full control over the analysis. The options of the main function are:

> library(coalescentMCMC)> args(coalescentMCMC)

function (x, ntrees = 3000, model = "constant", tree0 = NULL, printevery = 100, degree = 1, nknots = 0, knot.times = NULL, moves = 1:6)NULLwhere ntrees are the number of trees to output, and tree0 is the initial tree (if not provided, a UPGMA tree from a JC69-based distance matrix is used). model is either NULL in which case Θ is assumed to be constant, or "time" in which case a model where Θ follows an exponential growth is used.11 1 Other models will be implemented later. See the vignette “CoalescentModels”. Finally, printevery is an integer controlling the print frequency of the progress of the chain.

The current implementation uses neighborhood rearrangement as proposed in Kuhner et al. (1995) calling the function NeighborhoodRearrangement at each step of the chain. Five other tree moves are availables taken from Drummond et al. (2002). This can modified by using other functions described in ?treeOperators.

Let us now consider a very simple analysis with the woodmouse data available in ape. For the purpose of this vignette, we run a very light analysis in order to produce small outputs in a reasonable time.

> data(woodmouse)> out <- coalescentMCMC(woodmouse, ntrees = 300)

Running the Markov chain: Number of generations to run: 200Generation Nb of accepted trees 300 162Done.

The output object is of class "coda", so we can visualise it with the package of the same name (which has already been loaded):

> plot(out) The log-likelihood was relatively stable between −1870 and −1880. The trees are stored in a special place of the memory (an ‘environment’ in R’s jargon) from where they can be retrieved with a specific function:

> TR <- getMCMCtrees()> TR

300 phylogenetic treesNote that the trees generated during the burn-in period are not output, but the corresponding values of log-likelihood and Θ are. Hence out has 400 rows.

> dim(out)

[1] 300 3

> colnames(out)

[1] "logLik.tree" "logLik.coal" "theta"

We now run a model of time-dependent coalescent where Θ follows an exponential change through time:

> out2 <- coalescentMCMC(woodmouse, ntrees = 300, model = "time")

Running the Markov chain: Number of generations to run: 300Generation Nb of accepted trees 300 154Done.

> plot(out2) The change in log-likelihood along the chain is similar to what was observed above. The object out2 has now three columns:

> dim(out2)

[1] 300 4

> colnames(out2)

[1] "logLik.tree" "logLik.coal" "theta0" "rho"If we try to extract the trees as previously done and R is running in interactive mode, we will be asked which list of trees to extract:

> getMCMCtrees()Several lists of MCMC trees are stored:1 : TREES_0012 : TREES_002Return which number?It is also possible to extract the trees of a specific chain with its number, which is useful when the R code is not run interactively (such as this vignette):

> TR2 <- getMCMCtrees(2)

The parameters of the MCMC runs are stored separately and can be extracted with:

> getMCMCstats()

MCMC chain summaries (chains as columns): 001 002Nb of generations 300 300Nb of accepted moves 138 72

We can now compare both coalescent models: the two hypotheses under consideration are:

  • •

    H0: Θ is constant;

  • •

    H1: Θ changes through time following an exponential model.

Other things that could be done with simple R commands include:

  • •

    Compute confidence intervals around Θ^0 and ρ^ (alternatively, posterior distributions of these parameters if a Bayesian sampling is done);

  • •

    Re-run the chain(s) with different initial trees, for instance to run branching chains taking a tree from TR or TR2.

  • •

    Use other models of time-dependent coalescent (see the other vignette in this package).

References

  • [1] A. J. Drummond, G. K. Nicholls, A. G. Rodrigo, and W. Solomon (2002) Estimating mutation parameters, population history and genealogy simultaneously from temporally spaced sequence data. Genetics 161 (3), pp. 1307–1320. Cited by: Running Coalescent Analyses With coalescentMCMC.
  • [2] J. Felsenstein (2007) Trees of genes in populations. In Reconstructing Evolution: New Mathematical and Computational Advances, O. Gascuel and M. Steel (Eds.), pp. 3–29. Cited by: Running Coalescent Analyses With coalescentMCMC.
  • [3] M. K. Kuhner, J. Yamato, and J. Felsenstein (1995) Estimating effective population size and mutation rate from sequence data using Metropolis-Hastings sampling. Genetics 140, pp. 1421–1430. Cited by: Running Coalescent Analyses With coalescentMCMC.