| MRCA {TreeTools} | R Documentation |
Most recent common ancestor
Description
MRCA() calculates the last common ancestor of specified nodes.
Usage
MRCA(x1, x2, ancestors)
Arguments
x1, x2 |
Integer specifying index of leaves or nodes whose most recent common ancestor should be found. |
ancestors |
List of ancestors for each node in a tree. Perhaps
produced by |
Details
MRCA() requires that node values within a tree increase away from the root,
which will be true of trees listed in Preorder.
No warnings will be given if trees do not fulfil this requirement.
Value
MRCA() returns an integer specifying the node number of the last
common ancestor of x1 and x2.
Author(s)
Martin R. Smith (martin.smith@durham.ac.uk)
See Also
Other tree navigation:
AncestorEdge(),
CladeSizes(),
DescendantEdges(),
EdgeAncestry(),
EdgeDistances(),
ListAncestors(),
MatchEdges(),
NDescendants(),
NodeDepth(),
NodeNumbers(),
NodeOrder(),
RootNode()
Examples
tree <- BalancedTree(7)
# Verify that node numbering increases away from root
plot(tree)
nodelabels()
# ListAncestors expects a tree in Preorder
tree <- Preorder(tree)
edge <- tree$edge
ancestors <- ListAncestors(edge[, 1], edge[, 2])
MRCA(1, 4, ancestors)
# If a tree must be in postorder, use:
tree <- Postorder(tree)
edge <- tree$edge
ancestors <- lapply(seq_len(max(edge)), ListAncestors,
parent = edge[, 1], child = edge[, 2])