### Sources

#### R packages

`"ape"` (Paradis et al 2004)

`"TreeSim"` (Stadler 2014)

### Codes

We begin by simulating trees that we will use below to simulate traits.

Example 1: trees simulated by random splits

```library(ape)
tr <- rtree(10)
tr
```
```##
## Phylogenetic tree with 10 tips and 9 internal nodes.
##
## Tip labels:
## 	t2, t7, t5, t4, t10, t1, ...
##
## Rooted; includes branch lengths.
```
```TR <- rmtree(10, 10)
TR
```
```## 10 phylogenetic trees
```

The function `rmtree` calls repeatedly `rtree` and outputs the result in the appropriate format (here the object `TR`).

Example 2: trees simulated by speciation–extinction

```trbd <- rlineage(0.1, 0.05)
Ntip(trbd)
```
```##  24
```
```trbd2 <- rbdtree(0.1, 0.05)
Ntip(trbd2)
```
```##  22
```
```is.ultrametric(trbd)
```
```##  FALSE
```
```is.ultrametric(trbd2)
```
```##  TRUE
```
```is.ultrametric(drop.fossil(trbd))
```
```##  TRUE
```
```Ntip(drop.fossil(trbd))
```
```##  12
```

The function `rlineage` simulates a tree which includes the extinct species, so this tree is not ultrametric. The function `rbdtree` does the same but the extinct species are not output, so the final tree is ultrametric. The function `drop.fossil` deletes the lineages with no descendants at present (the end of the simulation). Note that the number of species at the end of the simulation (n) is a random variable.

Example 3: conditional simulation of speciation–extinction trees

The package `TreeSim` makes possible to simulate trees with a fixed value of n. The functions are `sim.bd.age`, `sim.bd.taxa`, and `sim.bd.taxa.age`, where the name of the function indicates whether the simulation is done with fixed T (`age`) and/or n (`taxa`).

In this example, we simulate two trees wiht n = 10, T = 50, λ = 0.1, and μ = 0.05:

```library(TreeSim)
TR2 <- sim.bd.taxa.age(n = 10, numbsim = 2, lambda = 0.1, mu = 0.05, age = 50)
TR2
```
```## []
##
## Phylogenetic tree with 10 tips and 9 internal nodes.
##
## Tip labels:
## 	t6, t9, t5, t8, t1, t3, ...
##
## Rooted; includes branch lengths.
##
## []
##
## Phylogenetic tree with 10 tips and 9 internal nodes.
##
## Tip labels:
## 	t1, t3, t6, t9, t5, t4, ...
##
## Rooted; includes branch lengths.
```

The trees are returned in a simple list, but the class can be changed easily:

```class(TR2) <- "multiPhylo"
TR2
```
```## 2 phylogenetic trees
```

The functions in this package have some options to simulate random sampling of taxa.

### References

• Paradis E, Claude J, Strimmer K (2004) APE: analyses of phylogenetics and evolution in R language. Bioinformatics 20:289-290
• Stadler T (2014). TreeSim: Simulating trees under the birth-death model. R package version 2.0. http://CRAN.R-project.org/package=TreeSim