# Re: [R-sig-phylo] Simulating tree from a given tree

```Dear Miguel & Eduardo.

```
This is correct, except that you should keep in mind that pbtree (like most, but not all, such simulators) generates trees from the first speciation event. Thus, the correct procedure must first involve drawing a wait time from an exponential distribution, deciding if the next event was a speciation or an extinction, attaching a stem to the base tree, and then (if the event was a speciation) simulating a birth-death tree to attach to this stem.

```
The algorithm would thus be something like:

```
1. Decide on a desired total height for the tree, h. (If, say, the tree has a current total height/depth of 100, this could be any value >100.)
```2. Go to a tip in the base tree. Compute it's height, t1.
```
3. Draw a random value from an exponential distribution, t2, with rate b+d for birth rate b & death rate d. 4. If t1+t2<h, add length t2 to the current tip and advance to 5. Otherwise, add h-t1 to the current tip and go to 2 for the next tip. 5. Decide if the current event is a speciation or extinction event. Draw a random value from a uniform distribution on (0,1). If that value is greater than b/(b+d) you are done with this tip: go back to step 2 for the next tip. Otherwise, advance to step 6. 6. Compute t3=h-(t1+t2). Simulate a birth-death tree for t3 with birth & death rates b & d. Attach the b/d tree to the current tip. Advance to the next tip & go back to step 2.
```
All the best, Liam

Liam J. Revell, Associate Professor of Biology
University of Massachusetts Boston
web: http://faculty.umb.edu/liam.revell/

On 7/30/2018 8:58 AM, Eduardo Ascarrunz wrote:
```
```Maybe you could use a birth-death model. You can estimate the speciation
rate and extinction rate from your original tree, and use those parameters
to run simulations of trees for 5 My with the pbtree function from
phytools. Run as many simulations as you have living tips in your original
tree, and bind each simulated tree to one of the living tips. It shouldn't
be too difficult to write a wrapper function to perform all those steps.

Cheers,

Eduardo

2018-07-29 11:06 GMT+02:00 <miguel.ve...@ext.uv.es>:

```
```Hi list:

Is there any function to simulate a tree from a given tree?. For example,
I have a tree encompassing 10 Million years and I would like to simulate
the "growth" of such tree for the following 5 MY.

Miguel VerdÃº

--
********************************************************************
Centro de Investigaciones sobre Desertificacion
(CSIC-UV-GV)
Carretera Moncada - NÃ¡quera, Km. 4,5
Spain
Tel +34 96 3424204
Fax +34 96 3424160
www.uv.es/verducam

_______________________________________________
R-sig-phylo mailing list - R-sig-phylo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo
Searchable archive at http://www.mail-archive.com/r-
sig-ph...@r-project.org/

```
```
[[alternative HTML version deleted]]

_______________________________________________
R-sig-phylo mailing list - R-sig-phylo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo
Searchable archive at http://www.mail-archive.com/r-sig-phylo@r-project.org/

```
```
_______________________________________________
R-sig-phylo mailing list - R-sig-phylo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo
Searchable archive at http://www.mail-archive.com/r-sig-phylo@r-project.org/
```