| count_clades_over_time {castor} | R Documentation |
Given a rooted phylogenetic tree whose edge lengths represent time intervals, calculate the number of clades at various time points (e.g., spanning from 0 to the maximum time of any tip). The root is interpreted as time 0, and the distance of any node or tip from the root is interpreted as time elapsed since the root. This function defines an equidistant sequence of time points, and counts how many edges "cross" each time point. Optionally, the slopes and relative slopes of the clade-counts-vs-time curve are also returned. The slopes and relative slopes are approximations for the species birth rate and the per-capita species birth rate (assuming no extinctions occurred).
count_clades_over_time( tree,
Ntimes = NULL,
min_time = NULL,
max_time = NULL,
times = NULL,
include_slopes= FALSE)
tree |
A rooted tree of class "phylo", where edge lengths represent time intervals (or similar). The root is assumed to be the unique node with no incoming edge. |
Ntimes |
Integer, number of equidistant time points for which to calculade clade counts. Can also be |
min_time |
Minimum time (distance from root) to consider. If |
max_time |
Maximum time (distance from root) to consider. If |
times |
Integer vector, listing time points (in ascending order) for which to calculate clade counts. Can also be |
include_slopes |
Logical, specifying whether the slope and the relative slope of the returned clades-per-time-point curve should also be returned. |
If tree$edge.length is missing, then every edge in the tree is assumed to be of length 1. The tree may include multi-furcations as well as mono-furcations (i.e. nodes with only one child). The tree need not be ultrametric, although in general this function only makes sense for dated trees (e.g., where edge lengths are time intervals or similar).
Either Ntimes or times must be non-NULL, but not both. If times!=NULL, then min_time and max_time must be NULL.
A list with the following elements:
Ntimes |
Integer, indicating the number of returned time points. Equal to the provided |
times |
Numeric vector of size Ntimes, listing the considered time points in increasing order. If |
diversities |
Integer vector of size Ntimes, listing the number of clades for each time point. |
slopes |
Numeric vector of size Ntimes, listing the slopes (finite-difference approximation of 1st derivative) of the curve clade_counts vs time_point. |
relative_slopes |
Numeric vector of size Ntimes, listing the relative slopes of the curve clade_counts vs time_point, i.e. |
Stilianos Louca
# generate a random tree tree = generate_random_tree(list(birth_rate_intercept=1), max_tips=1000)$tree # count clades over time results = count_clades_over_time(tree, Ntimes=100) # plot curve (number of clades vs time) plot(results$times, results$diversities, type="l", xlab="time", ylab="# clades")