get_mrca_of_set {castor} | R Documentation |
Given a rooted phylogenetic tree and a set of tips and/or nodes ("descendants"), calculate the most recent common ancestor (MRCA) of those descendants.
get_mrca_of_set(tree, descendants)
tree |
A rooted tree of class "phylo". The root is assumed to be the unique node with no incoming edge. |
descendants |
An integer vector or character vector, specifying the tips/nodes for which to find the MRCA. If an integer vector, it must list indices of tips (from 1 to Ntips) and/or nodes (from Ntips+1 to Ntips+Nnodes), where Ntips and Nnodes is the number of tips and nodes in the tree, respectively. If a character vector, it must list tip and/or node names. In this case |
The 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). Duplicate entries in descendants
are ignored.
An integer in 1,..,(Ntips+Nnodes), representing the MRCA using the same index as in tree$edge
. If the MRCA is a tip, then this index will be in 1,..,Ntips. If the MRCA is a node, then this index will be in (Ntips+1),..,(Ntips+Nnodes).
Stilianos Louca
get_pairwise_mrcas
, get_tips_for_mrcas
# generate a random tree Ntips = 1000 tree = generate_random_tree(list(birth_rate_intercept=1),Ntips)$tree # pick 3 random tips or nodes descendants = sample.int(n=(Ntips+tree$Nnode), size=3, replace=FALSE) # calculate MRCA of picked descendants mrca = get_mrca_of_set(tree, descendants)