macroevolution / bammtools

BAMMtools is an R package for analysis of BAMM results
10 stars 6 forks source link

Inconsistent nodesets b/w getCladeRates() & getRateThroughTimeMatrix() #48

Closed davidcerny closed 2 years ago

davidcerny commented 2 years ago

I'm not sure whether this is a bug or intended behavior, but I could not find it documented anywhere:

I recently ran a BAMM analysis that found 2 shifts in the MAP configuration; when I generated separate rate matrices using getRateThroughTimeMatrix() for the two shifted clades and plotted the rates through time, clade 2 appeared to have shifted to substantially higher speciation and net. div. rates than clade 1. However, when I used getCladeRates() to calculate exactly how much faster their rates were compared to the background regime, I got higher values for clade 1 than for clade 2.

It turned out that this is because the target node itself is included in the nodeset vector by getCladeRates() but excluded from it by getRateThroughTimeMatrix(), which contains the following conditional:

if (!is.null(node)) {
      if (nodetype == "include") {
            nodeset <- nodeset[nodeset != node]
      }
}

Again, I'm not sure whether this difference in nodeset treatment between the two functions is intentional, but it seems like it can lead to potentially confusing output.

ptitle commented 2 years ago

Thank you @davidcerny for pointing out this discrepancy. We took a closer look, and indeed, the specified node should not be removed from the nodeset in getRateThroughTimeMatrix. The two functions should be treating the nodeset in the same way.

The update has been made here on github, but I am waiting for a dependency issue to be resolved before I push to CRAN.