Function to make the most recent common ancestor (MRCA) matrix of a tree, where entry (i,j) gives the MRCA of tips i and j. The function is linear, exploiting the fact that the tree is rooted.
linearMrca(tree, k = 0)
an object of the class phylo
which should be rooted.
(optional) number of tips in tree, for faster computation
## generate a random tree
x <- rtree(6)
## create matrix of MRCAs: entry (i,j) is the node number of the MRCA of tips i and j
linearMrca(x,6)
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] 1 8 7 7 7 7
#> [2,] 8 2 7 7 7 7
#> [3,] 7 7 3 9 9 9
#> [4,] 7 7 9 4 11 10
#> [5,] 7 7 9 11 5 10
#> [6,] 7 7 9 10 10 6