R: Extend a rooted tree up to a specific height.

extend_tree_to_height {castor} | R Documentation

## Extend a rooted tree up to a specific height.

### Description

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.

### Usage

    extend_tree_to_height(tree, new_height=NULL)

### Arguments

`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 `NULL` or negative, then it is set to the maximum distance of any tip from the root.

### Details

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.

### Value

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.

### Author(s)

Stilianos Louca

### See Also

`trim_tree_at_height`

### Examples

    # 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))

[Package castor version 1.6.8 Index]