get_all_node_depths {castor} | R Documentation |
Get the phylogenetic depth of each node in a tree.
Description
Given a rooted phylogenetic tree, calculate the phylogenetic depth of each node (mean distance to its descending tips).
Usage
get_all_node_depths(tree, as_edge_count=FALSE)
Arguments
tree |
A rooted tree of class "phylo". The root is assumed to be the unique node with no incoming edge. |
as_edge_count |
Logical, specifying whether distances should be counted in number of edges, rather than cumulative edge length. This is the same as if all edges had length 1. |
Details
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 asymptotic average time complexity of this function is O(Nedges), where Nedges is the number of edges in the tree.
Value
A numeric vector of size Nnodes, with the i-th element being the mean distance of the i-th node to all of its tips.
Author(s)
Stilianos Louca
See Also
Examples
# generate a random tree
Ntips = 1000
tree = generate_random_tree(list(birth_rate_intercept=1,
death_rate_intercept=0.5),
max_tips=Ntips)$tree
# calculate node phylogenetic depths
node_depths = get_all_node_depths(tree)
# plot histogram of node depths
hist(node_depths, xlab="phylogenetic depth", ylab="# nodes", prob=FALSE);