Learn R Programming

castor (version 1.6.1)

count_tips_per_node: Count descending tips.

Description

Given a rooted phylogenetic tree, count the number of tips descending (directy or indirectly) from each node.

Usage

count_tips_per_node(tree)

Arguments

tree

A rooted tree of class "phylo". The root is assumed to be the unique node with no incoming edge.

Value

An integer vector of size Nnodes, with the i-th entry being the number of tips descending (directly or indirectly) from the i-th node.

Details

The asymptotic time complexity of this function is O(Nedges), where Nedges is the number of edges.

See Also

get_subtree_at_node

Examples

Run this code
# NOT RUN {
# generate a tree using a simple speciation model 
tree = generate_random_tree(list(birth_rate_intercept=1),max_tips=1000)$tree

# count number of tips descending from each node
tips_per_node = count_tips_per_node(tree);

# plot histogram of tips-per-node
barplot(table(tips_per_node[tips_per_node<10]), xlab="# tips", ylab="# nodes")
# }

Run the code above in your browser using DataLab