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)
## 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 9 8 8 7 7
#> [2,] 9 2 8 8 7 7
#> [3,] 8 8 3 10 7 7
#> [4,] 8 8 10 4 7 7
#> [5,] 7 7 7 7 5 11
#> [6,] 7 7 7 7 11 6