sim.phy: Simulate phylogenies

sim.phyR Documentation

Simulate phylogenies


Simulate phylogenies under pure birth/death or as a function of trait evolution

Usage = 0.1, extinction = 0.025, time.steps = 20)
  speciate = 0.1,
  extinction = 0.025,
  time.steps = 20,
  tr.range = c(0, 1), = 2, = 1,
  tr.walk = 0.2,
  tr.wrap = TRUE

edge2phylo(edge, s, e = numeric(0), el = NA, t = NULL)



probability each species will speciate in each time-step (0-1)


probability each species will go extinct in each time-step (0-1)


number of time-steps for simulation


vector of length two specifying boundaries for trait values (see notes); initial two species will be at the 25th and 75th percentiles of this space. See also tr.wrap

speciation rate's interaction with the minimum distance between a species and the species most similar to it (see details)

extinction rate's interaction with the minimum distance between a species and the species most similar to it (see details)


at each time-step a species not undergoing speciation or extinction has its trait value drawn from a distribution centered at its current value and with a standard deviation set by this value. I.e., this is the rate of the Brownian motion trait evolution.


whether to force species' trait values to stay within the boundary defined by tr.range; default TRUE.


a two-column matrix where the first column is the start node, the second the destination, as in phylo$edge


which of the rows in the edge matrix represent extant species


which of the tips in the edge matrix are extinct (DEFAULT: empty vector, i.e., none)


a vector to be used to give edge.length to the phylogeny (default NA, i.e., none)


if given (default NA), a vector to be used for traits ($traits slot) in the phylogeny

Details simulates a pure birth/death speciation model. There are two important things to note: (1) speciation is randomised before extinction, and only one thing can happen to a lineage per timestep. (2) This code works well for my purposes, but absurd parameter values can cause the function to crash. is an extension of, and all its caveats apply to it. It additionally simulated the evolution of a trait under Brownain motion (tr.walk). Species' speciation/extinction rates change depending on whether they have a trait value similar to other species (, When a speciation event happens, the two daughters split evenly about the ancestor's trait value, taking values half-way to whatever the nearest species' value is. To be precise: p(speciate) = speciate +*, p(extinct) = extinction +*, where i denotes each species.

edge2phylo is an internal function for the sim.phy and sim.meta function families, which may be of use to you. Check those functions' code for examples of use.

These functions are closely related to sim.meta; the latter are extensions that simulate meta-community structure at the same time.


phylo object with random tip.labels, and trait values if using


Will Pearse

Will Pearse

Will Pearse

See Also

sim.meta scape


tree <-, 0, 10)

pez documentation built on Sept. 1, 2022, 1:09 a.m.