expoTree is an R packge to calculate the likelihood of the a phylogenetic tree, under the assumption of a stochastic susceptible-infected model for the underlying population dynamics.

expoTree is not yet available on CRAN, so you have to download and install it "manually". Make sure that you have a C/C++ and a FORTRAN compiler installed.


CRAN installation

expoTree is now available on CRAN! Enter


in an R console or choose from the list of available packages.

Source installation

Download the latest release from the "Downloads" section or clone the Git repository to get the latest version.

git clone https://bitbucket.org/gaberoo/expotree.git

If you downloaded a package, type the following on the command line

R CMD INSTALL expoTree_{currentVersion}.tar.gz

Replace {currentVersion} with whatever version you installed. If you clone the Git repo,

R CMD INSTALL expotree

You can now use the library in R.


Check the R help files for a detailed description. Here's a quick-and-dirty example:


# simulate trees
N <- 15
beta <- 1
mu <- 0.1
psi <- 0.1
rho <- 0
nsamp <- 20
forest <- lapply(1:2,function(x) sim.trees(N,beta,mu,psi,nsamp))

# plot lineages-through-time

extant <- sapply(forest,function(t) sum(2*t[,2]-1))
lineages <- lapply(forest,function(t) sum(2*t[,2]-1)+cumsum(1-2*t[,2]))
max.lineages <- sapply(lineages,max)

# calculate likelihood for the forest
lik <- sapply(forest,function(tree) {
cat("Likelihood = ",sum(lik),"\n")

if (! is.nan(lik)) {
  # Find optimal parameters
  opt <- expoTree.optim(forest,

MCMC and expoTree

You can of course use expoTree together with MCMC packages in R. However, I strongly suggest that you use the pure C version if you plan on performing Bayesian inference. It conatins a C implementation of the DREAM algorithm doi:10.1515/IJNSNS.2009.10.3.273. The DREAM algorithm speeds of convergence of the Metropolis-Hastings algorithm, which is great because the calculation of the likelihood is really expensive.