To simulate, we first need our instantaneous transition matrix, Q. Let's make Q symmetric, but with uneven rates among states. For fun, let's also call our three states "blue", "green", and "red".
> source("sim.history.R")
> Q<-matrix(c(-1,0.8,0.2,0.8,-1.2,0.4,0.2,0.4,-0.6),3,3, dimnames=list(c("red","green","blue"),c("red","green","blue")))
> Q
red green blue
red -1.0 0.8 0.2
green 0.8 -1.2 0.4
blue 0.2 0.4 -0.6
Now let's get a stochastic birth-death tree:
> require(ape)
> tree<-rbdtree(birth=1.0,death=0.0,Tmax=log(25/2))
Finally, let's simulate on the tree & plot:
> mtree<-sim.history(tree,Q)
> cols<-rownames(Q); names(cols)<-rownames(Q)
> plotSimmap(mtree,cols)
And we get the following (obviously individual results will vary):

Both the node & tip states are also stored in the modified "phylo" object: here as $node.states and $states. I include this mainly to facilitate some analyses that I have been working on.
This function should be added to the next version of "phytools".
thanks
ReplyDelete. For instance, a statue of King Kamehamea, viewed as the best of Hawaii's rulers, is situated on the Big Island.view my website
ReplyDelete