extend_tree_to_height {castor} | R Documentation |
Given a rooted phylogenetic tree and a specific distance from the root (“new height”), elongate terminal edges (i.e. leading into tips) as needed so that all tips have a distance from the root equal to the new height. If a tip already extends beyond the specified new height, its incoming edge remains unchanged.
extend_tree_to_height(tree, new_height=NULL)
tree |
A rooted tree of class "phylo". The root is assumed to be the unique node with no incoming edge. |
new_height |
Numeric, specifying the phylogenetic distance from the root to which tips are to be extended. If |
The input tree may include multi-furcations (i.e. nodes with more than 2 children) as well as mono-furcations (i.e. nodes with only one child). All tip, edge and node indices remain unchanged. This function provides a quick-and-dirty way to make a tree ultrametric, or to correct small numerical inaccuracies in supposed-to-be ultrametric trees.
A list with the following elements:
tree |
A new rooted tree of class "phylo", representing the extended tree. |
max_extension |
Numeric. The largest elongation added to a terminal edge. |
Stilianos Louca
# generate a random non-ultrametric tree tree = generate_random_tree(list(birth_rate_intercept=1,death_rate_intercept=0.5), max_time=1000, coalescent=FALSE)$tree # print min & max distance from root span = get_tree_span(tree) cat(sprintf("Min & max tip height = %g & %g\n",span$min_distance,span$max_distance)) # make tree ultrametric by extending terminal edges extended = extend_tree_to_height(tree)$tree # print new min & max distance from root span = get_tree_span(extended) cat(sprintf("Min & max tip height = %g & %g\n",span$min_distance,span$max_distance))