allnode.times: allnode.times

View source: R/allnode.times.R

allnode.timesR Documentation

allnode.times

Description

allnode.times is used to obtain the ages of all nodes in the tree. It is similar to branching.times() in ape, but it also returns the ages of the tips. This is particularly useful for heterochronous trees.

Usage

allnode.times(phylo, tipsonly = FALSE)

Arguments

phylo

A phylogenetic tree of class 'phylo'

tipsonly

A logical (T / F). With T, the function returns the ages of the tips only. With F, it returns the ages of the tips and internal nodes.

Details

This function is similar to branching.times, but it also returns the ages of the tips. In ultrametric trees, the ages of all tips are 0, but in heterocrhonous trees they can have different ages.

Value

A vector with the ages of all nodes in the tree. The youngest tip always has age 0. The items of the vector are numbered according to the 'phylo' object. To inspect the numbering of the tips and internal nodes see the example.

Note

None

Author(s)

David Duchene and Sebastian Duchene

References

Pending.

See Also

branching.times() from package 'ape'

Examples

set.seed(12345)
myTree <- rtree(10)
plot(myTree)
# See the numbering of internal nodes and tips. Note that the tip labels and the actual numbering of the tips are different.
nodelabels()
tiplabels()
allnode.times(myTree)

# Plot the tree and add the ages of the tips and internal nodes.
plot(myTree, show.tip.label = FALSE)
allTimes <- allnode.times(myTree)
allTimes
tiplabels(round(allTimes[1:10]))
nodelabels(round(allTimes[11:19]))


## The function is currently defined as
function (phylo, tipsonly = FALSE) 
{
    require(phangorn)
    di.phylo <- dist.nodes(phylo)
    root.phylo <- phylo$edge[, 1][!(phylo$edge[, 1] %in% phylo$edge[, 
        2])][1]
    phylo.depth <- max(di.phylo[as.numeric(colnames(di.phylo)) == 
        root.phylo, ])
    node.times <- phylo.depth - di.phylo[as.numeric(rownames(di.phylo)) == 
        root.phylo, ]
    if (tipsonly == TRUE) {
        node.times <- phylo.depth - di.phylo[as.numeric(rownames(di.phylo)) == 
            root.phylo, 1:length(phylo$tip.label)]
    }
    return(node.times)
  }

sebastianduchene/NELSI documentation built on Aug. 18, 2022, 11:45 p.m.