| simulate_diversification_model {castor} | R Documentation |
Simulate a speciation/extinction model for diversity over time, corresponding to a tree generation model. Speciation (birth) and extinction (death) rates can each be constant or power-law functions of the number of extant species. For example,
B = I + F\cdot N^E,
where B is the birth rate, I is the intercept, F is the power-law factor, N is the current number of extant species and E is the power-law exponent. Note that currently only the deterministic version of the model can be simulated; for the stochastic version (Poisson process) see generate_random_tree.
simulate_diversification_model( times,
parameters = list(),
start_time = NULL,
start_diversity = 1,
coalescent = FALSE,
reverse = FALSE,
include_event_rates = FALSE,
include_Nevents = FALSE,
max_runtime = NULL)
times |
Numeric vector, listing the times for which to calculate diversities, as predicted by the model. Values must be in ascending order. |
parameters |
A named list specifying the birth-death model parameters, with one or more of the following entries:
|
start_time |
Numeric. If |
start_diversity |
Numeric. True diversity at |
coalescent |
Logical, specifying whether the diversity corresponding to a coalescent tree (i.e. the tree spanning only extant tips) should be calculated. If |
reverse |
Logical. If |
include_event_rates |
Logical. If |
include_Nevents |
Logical. If |
max_runtime |
Numeric. Maximum runtime (in seconds) allowed for the simulation. If this time is surpassed, the simulation aborts. |
In the special case where per-capita birth and death rates are constant (i.e. I=0 and E=1 for birth and death rates), this function uses an explicit analytical solution to the underlying differential equations, and is thus much faster than in the general case.
A named list with the following elements:
success |
Logical, indicating whether the simulation was successful. If the simulation aborted due to runtime constraints (option |
diversities |
Numeric vector of the same size as |
birth_rates |
Numeric vector of the same size as |
death_rates |
Numeric vector of the same size as |
Nbirths |
Numeric vector of the same size as |
Ndeaths |
Numeric vector of the same size as |
Stilianos Louca
generate_random_tree,
count_clades_over_time
# Generate a tree
max_time = 100
parameters = list(birth_rate_intercept = 1,
birth_rate_factor = 0,
birth_rate_exponent = 0,
death_rate_intercept = 0,
death_rate_factor = 0,
death_rate_exponent = 0)
tree = generate_random_tree(parameters,max_time=max_time)$tree
# Calculate diversity-vs-time curve for the tree
times = seq(from=0,to=0.99*max_time,length.out=10)
tree_diversities = count_clades_over_time(tree, times=times)$diversities
# simulate diversity curve based on deterministic model
model_diversities = simulate_diversification_model(times,parameters)$diversities
# compare diversities in the tree to the simulated ones
plot(tree_diversities,model_diversities,xlab="tree diversities",ylab="simulated diversities")
abline(a=0,b=1,col="#A0A0A0") # show diagonal for reference