parsimonyNumber
aims at finding the number of equivalent allocations of
the shifts on the tree, i.e allocations that are parsimonious and compatible
with a given clustering of the tips.
phylogenetic tree, class phylo
.
the vector of the clusters of the tips. Default to all the tips in one single cluster.
an object of S3 class "parsimonyNumber
" with:
a (ntaxa + Nnode) x (nclus) matrix of locally parsimonious solutions starting from a cluster k at a given node
an object of class "parsimonyCost
",
result of function parsimonyCost
.
This function does a recursion up the tree.
The function extract.parsimonyNumber
gives the result sought for
any subtree.
The matrix of costs of the states (number of shifts) is also required, it is
computed by function parsimonyCost
.
tree <- read.tree(text="(((0,1),2),2);")
plot(tree); nodelabels()
clusters <- c(0, 1, 2, 2)
n_sols <- parsimonyNumber(tree, clusters)
n_sols
#>
#> Number of parsimonious solutions: 3.
#>
## Extract the number of parsimonious solutions at the root
extract(n_sols)
#> [1] 3
## Extract the cost of the solutions from the root
extract(n_sols, what = "cost")
#> [1] 2
extract(parsimonyCost(tree, clusters)) # same, more efficient
#> [1] 2
## Extract for the sub-tree below node 7
extract(n_sols, 7) # Result: 2 (the ancestral state is either "0" or "1").
#> [1] 2