This loops over all internal nodes in the tree and takes the sum over all descendant taxa, for each sample.
Value
A named list where each element corresponds to an internal node (by node label) and contains a vector of totals for each sample, computed by summing abundances over all descendant tips.
Examples
library(ape)
tree <- rtree(5)
x_mat <- matrix(runif(15), ncol = 5)
colnames(x_mat) <- tree$tip.label
tree$node.label <- as.character(seq_len(tree$Nnode))
node_totals(tree, x_mat)
#> $`1`
#> [1] 3.317996 1.682202 2.121190
#>
#> $`2`
#> [1] 2.492797 1.408383 1.551145
#>
#> $`3`
#> [1] 1.2857627 0.5638587 0.9927600
#>
#> $`4`
#> [1] 1.2070343 0.8445247 0.5583851
#>