sim.history {phytools}R Documentation

Simulate stochastic character history under some model


This function simulates a stochastic character history for a discretely valued character trait on the tree. The resultant tree is stored as a modified "phylo" object in stochastic character map (e.g., make.simmap) format.


sim.history(tree, Q, anc=NULL, nsim=1, ...)



a phylogenetic tree as an object of class "phylo".


a matrix containing the instantaneous transition rates between states. Note that normally this is the transpose of the matrix produced by fitDiscrete in the geiger package or make.simmap in phytools; that is to say the transition rate from i -> j should be given by Q[j,i]. However, if your matrix is properly conformed (i.e., rows or columns sum to 0), then sim.history will attempt to transpose your matrix correctly & will return an informative message (if message=TRUE, see below).


an optional value for the state at the root node; if NULL, a random state will be assigned.


number of simulations.


other optional arguments. Currently only message, a logical value indicating whether or not to turn on informational messages (defaults to message=TRUE).


A modified phylogenetic tree of class "phylo" (or a modified "multiPhylo" object, for nsim > 1) with the following additional elements:


a list of named vectors containing the times spent in each state on each branch, in the order in which they occur.


a matrix containing the total time spent in each state along each edge of the tree.


a vector containing the tip states.


a matrix containing the states at internal & terminal nodes (according to the dimensions of edge).


Liam Revell


Revell, L. J. (2012) phytools: An R package for phylogenetic comparative biology (and other things). Methods Ecol. Evol., 3, 217-223.

See Also

make.simmap, read.simmap, plotSimmap, sim.rates

[Package phytools version 0.4-60 Index]