ScottClaessens / coevolve

coevolve R package for Bayesian dynamic coevolutionary models using Stan
GNU General Public License v2.0
7 stars 0 forks source link

Print error message if tree has no branch lengths #33

Closed ScottClaessens closed 2 months ago

ScottClaessens commented 2 months ago

Currently, the package allows users to include trees that have no branch lengths. The model fails to fit in this case.

library(ape)
library(coevolve)
set.seed(1)
n <- 10
tree <- rtree(n, br = NULL) # no branch lengths
d <- data.frame(
  id = tree$tip.label,
  x = rnorm(n),
  y = rnorm(n)
  )
m <- coev_fit(
  data = d,
  variables = list(
    x = "normal",
    y = "normal"
  ),
  id = "id",
  tree = tree
)
# Chain 4 Rejecting initial value:
#Chain 4   Error evaluating the log probability at the initial value.
#Chain 4 Exception: cholesky_decompose: Matrix m is not positive definite
# Warning messages:
#1: All chains finished unexpectedly! Use the $output(chain_id) method for more information.

Since the model fundamentally depends on branch lengths, we should preclude users from entering trees like this. I will add an error message.

ScottClaessens commented 2 months ago

Fixed in 6421ba9. Above code now produces error message:

Error: Argument 'tree' does not include branch lengths.