Simulate stochastic character maps on a phylogenetic tree or trees
This function performs stochastic mapping using several different alternative methods.
For Q="empirical"
, make.simmap
first fits a continuous-time reversible Markov model for the evolution of x
and then simulates stochastic character histories using that model and the tip states on the tree. This is the same procedure that is described in Bollback (2006), except that simulation is performed using a fixed value of the transition matrix, Q, instead of by sampling Q from its posterior distribution.
For Q="mcmc"
, make.simmap
first samples Q nsim
times from the posterior probability distribution of Q using MCMC, then it simulates nsim
stochastic maps conditioned on each sampled value of Q.
For Q
set to a matrix, make.simmap
samples stochastic mappings conditioned on the fixed input matrix.
make.simmap(tree, x, model="SYM", nsim=1, ...)
tree |
a phylogenetic tree as an object of class |
x |
a vector containing the tip states for a discretely valued character, or a matrix containing the prior probabilities of tip states in rows and character states as column names. The names (if |
model |
a character string containing the model or a transition model specified in the form of a matrix. See |
nsim |
number of simulations. If |
... |
optional arguments. So far, |
make.simmap
uses code modified from ace
(by Paradis et al.) to perform Felsenstein's pruning algorithm to compute the likelihood.
As of phytools >= 0.2-33 x
can be a vector of states or a matrix containing the prior probabilities of tip states in rows. In this case the column names of x
should contain the states, and the row names should contain the tip names.
Note that there was a small (but potentially significant) bug in how node states were simulated by make.simmap
in versions of phytools <= 0.2-26. Between phytools 0.2-26 and 0.2-36 there was also a bug for asymmetric models of character change (e.g., model="ARD"
). Finally, between phytools 0.2-33 and phytools 0.2-47 there was an error in use of the conditional likelihoods for the root node, which caused the root node of the tree to be sampled incorrectly. These issues should be fixed in all later versions.
Q="mcmc"
and Q
set to a fixed value were introduced to phytools >= 0.2-53.
If tree
is an object of class "multiPhylo"
then nsim
stochastic maps are generated for each input tree.
A object of class "simmap"
or "multiSimmap"
which consists of an object of class "phylo"
(or a list of such objects with class "multiPhylo"
), with the following additional elements:
maps |
a list of named vectors containing the times spent in each state on each branch, in the order in which they occur. |
mapped.edge |
a matrix containing the total time spent in each state along each edge of the tree. |
Q |
the assumed or sampled value of |
logL |
the log-likelihood of the assumed or sampled |
Liam Revell liam.revell@umb.edu
Bollback, J. P. (2006) Stochastic character mapping of discrete traits on phylogenies. BMC Bioinformatics, 7, 88.
Huelsenbeck, J. P., R. Neilsen, and J. P. Bollback (2003) Stochastic mapping of morphological characters. Systematic Biology, 52, 131-138.
Paradis, E., J. Claude, and K. Strimmer (2004) APE: Analyses of phylogenetics and evolution in R language. Bioinformatics, 20, 289-290.
Revell, L. J. (2012) phytools: An R package for phylogenetic comparative biology (and other things). Methods Ecol. Evol., 3, 217-223.
## load tree and data from Revell & Collar (2009) data(sunfish.tree) data(sunfish.data) ## extract discrete character (feeding mode) fmode<-setNames(sunfish.data$feeding.mode, rownames(sunfish.data)) ## do stochastic mapping smap.trees<-make.simmap(sunfish.tree,fmode,model="ER", nsim=100) ## print a summary of the stochastic mapping summary(smap.trees) ## plot a posterior probabilities of ancestral states cols<-setNames(c("blue","red"),levels(fmode)) plot(summary(smap.trees),colors=cols,ftype="i") legend("topleft",c("non-piscivorous","piscivorous"), pch=21,pt.bg=cols,pt.cex=2) par(mar=c(5.1,4.1,4.1,2.1)) ## plot posterior density on the number of changes plot(density(smap.trees),bty="l") title(main="Posterior distribution of changes of each type", font.main=3)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.