library(ape)
library(phytools)
data(Cetacea)
plot(Cetacea)
tot_time<-max(node.age(Cetacea)$ages)
# slice the Cetaceae tree 10 Myr ago:
time_stop=10
sliced_tree <- Cetacea
sliced_sub_trees <- treeSlice(sliced_tree,slice = tot_time-time_stop, trivial=TRUE)
for (i in 1:length(sliced_sub_trees)){
if (Ntip(sliced_sub_trees[[i]])>1){
sliced_tree <- drop.tip(sliced_tree,
tip=sliced_sub_trees[[i]]$tip.label[2:Ntip(sliced_sub_trees[[i]])])
}}
for (i in which(node.depth.edgelength(sliced_tree)>(tot_time-time_stop))){
temp = sliced_tree$edge.length[which(sliced_tree$edge[,2]==i)]-time_stop
sliced_tree$edge.length[which(sliced_tree$edge[,2]==i)] <- temp
}
Ntip(sliced_tree) # 27 lineages present 10 Myr have survived until today
# Now we can fit birth-death models excluding the 10 last Myr
# Fit the pure birth model (no extinction) with a constant speciation rate
f.lamb <-function(t,y){y[1]}
f.mu<-function(t,y){0}
lamb_par<-c(0.09)
mu_par<-c()
result_cst <- fit_bd_in_past(sliced_tree, tot_time, time_stop, f.lamb, f.mu,
desc=Ntip(Cetacea), tot_desc=89, lamb_par, mu_par,
cst.lamb = TRUE, fix.mu=TRUE, dt=1e-3)
Run the code above in your browser using DataLab