# to check the usage of the function, let us make sure it transforms a
# phylogeny generated with make.phylo back into the original simulation
###
# birth-death process
# set seed
set.seed(1)
# run simulation
sim <- bd.sim(1, lambda = 0.3, mu = 0.1, tMax = 10, nFinal = c(10, Inf))
# convert birth-death into phylo
phy <- make.phylo(sim)
# convert phylo into a sim object again
res <- phylo.to.sim(phy = phy, extant = sim$EXTANT, mothers = sim$PAR)
# test if simulation and converted object are the same
all.equal(sim, res)
###
# birth-death process with extinct lineages:
# set seed
set.seed(1)
# run simulation
sim <- bd.sim(1, lambda = 0.1, mu = 0.3, tMax = 10, nFinal = c(2, 4))
# convert birth-death into phylo
phy <- make.phylo(sim)
# convert phylo into a sim object again
res <- phylo.to.sim(phy = phy, extant = sim$EXTANT, mothers = sim$PAR, stemAge = max(sim$TS))
# test if simulation and converted object are the same
all.equal(sim, res)
###
# pure birth process
# set seed
set.seed(1)
# run simulation
sim <- bd.sim(1, lambda = 0.2, mu = 0, tMax = 10, nFinal = c(10, Inf))
# convert birth-death into phylo
phy <- make.phylo(sim)
# convert phylo into birth-death again
# note we can supply optional arguments, see description above
res <- phylo.to.sim(phy = phy, extant = sim$EXTANT, mothers = sim$PAR,
stemAge = 10, stemLength = (10 - sim$TS[2]))
# testing if simulation and converted object are the same
all.equal(sim, res)
Run the code above in your browser using DataLab