# function to simulate a pure-birth phylogenetic tree or trees # written by Liam J. Revell 2011-2013 pbtree<-function(b=1,n=NULL,t=NULL,scale=NULL,nsim=1,ape=TRUE){ if(nsim>1){ trees<-replicate(nsim,pbtree(b,n,t,scale),simplify=FALSE) class(trees)<-"multiPhylo" return(trees) } else { if(!is.null(n)&&!is.null(t)){ cat("simulating with both taxa-stop (n) and time-stop is\n") cat("performed via rejection sampling & may be slow\n\n") N<-0; count<--1 while(N!=n){ tree<-pbtree(b,t=t,ape=FALSE) N<-length(tree$tip.label) count<-count+1 } cat(paste(" ",count," trees rejected before finding a tree\n\n",sep="")) } else { if(!is.null(t)){ node<-1 edge<-matrix(c(node,NA,node,NA),2,2,byrow=T) edge.length<-c(0,0) node<-node+1; tip<-0; tt<-0 while(ttt) l<-l-tt+t if(tt