Sunday, March 31, 2013

Random trees for a set of taxa

A phytools user recently asked:

"Is there any function in your package that can randomize the shape of a phylogeny? e.g. randomize the topology of a phylogenetic tree?

I'm going to liberally interpret this to mean - how do we simulate random trees for a set of tip taxa?

This is straightforward using the phytools function pbtree, but we could equally well substitute rtree from ape, birthdeath.tree in geiger, or any of the more flexible tree simulation functions in TreeSim; basically anything that creates an object of class "multiPhylo".

Here's how we do it:

# for our simulations, let's set...

# simulate random trees (using any simulator)
# now apply our tip labels
   function(x,sp){ x$tip.label<-sample(sp); x },

That's it.


  1. Also, if anyone is interested in only partially randomizing taxon placement on a cladogram, they could randomly collapse nodes with di2multi in ape (or more simply with degradeTree in paleotree) and then randomly resolve those nodes with multi2di. This would produce trees that would only partially share some splits/nodes.


Note: due to the very large amount of spam, all comments are now automatically submitted for moderation.