Closed fcampelo closed 3 years ago
Hi Felipe,
Yes that's strange. The tree is kept ultrametric in only a small proportion of cases (random = TRUE
is the default):
R> expr <- expression(is.ultrametric(multi2di(my.tree)))
R> res <- replicate(1000, eval(expr))
R> table(res)
res
FALSE TRUE
962 38
But if you change the option equiprob
, the results are as expected:
R> expr <- expression(is.ultrametric(multi2di(my.tree, equiprob = FALSE)))
R> res <- replicate(1000, eval(expr))
R> table(res)
res
TRUE
1000
You can also have always TRUE if you increase the value of the option tol
in multi2di
with the default equiprob = TRUE
. Anyway, there should be no difference between both solutions. I'm going to have a closer look at it. Thanks for reporting this.
Best,
Emmanuel
Hi Emmanuel,
Thank you for the feedback! The first option (equiprob = FALSE
works like a charm, but the second one (increasing tol
) doesn't:
R> expr <- expression(is.ultrametric(multi2di(my.tree, tol = 1e-5)))
R> res <- replicate(1000, eval(expr))
R> table(res)
res
FALSE TRUE
961 39
R> expr <- expression(is.ultrametric(multi2di(my.tree, tol = 1e-3)))
R> res <- replicate(1000, eval(expr))
R> table(res)
res
FALSE TRUE
978 22
R> expr <- expression(is.ultrametric(multi2di(my.tree, tol = .1)))
R> res <- replicate(1000, eval(expr))
R> table(res)
res
FALSE TRUE
969 31
R> expr <- expression(is.ultrametric(multi2di(my.tree, tol = 1)))
R> res <- replicate(1000, eval(expr))
R> table(res)
res
FALSE TRUE
967 33
Oops! My mistake: tol
is an option of is.ultrametric
, not multi2di
. Coincidentally, di2multi
has also this option...
Hi @fcampelo & @emmanuelparadis,
it is a problem with rtopology
, as
> ape::is.ultrametric(ape::multi2di(my.tree, random = TRUE, equiprob=FALSE))
[1] TRUE
which calls rtree
works fine. I assume rtree
used to be the default.
If you replace rtopology
with the following
fun <- function(N){
x <- rtopology(N, rooted = TRUE)
desc <- x$edge[,2]
ind <- desc<=N
x$edge[ind, 2] <- seq_len(N)
x$tip.label <- x$tip.label[desc[ind]]
x
}
inside .multi2di_ape
it works. Maybe not really elegant.
Cheers,
Klaus
Hi @KlausVigo,
Thanks! I've found something even less elegant:
FUN <- function(N) {
tr <- rtopology(N, rooted = TRUE)
tr <- read.tree(text = write.tree(tr))
tr$edge
}
I'll test later which one's best. Cheers, Emmanuel
I pushed a fix on the function ape::::.multi2di_ape
. It has this bit of code:
if (random) {
if (equiprob) {
FUN <- function(N) {
x <- rtopology(N, rooted = TRUE)$edge
desc <- x[, 2L]
x[desc <= N, 2L] <- seq_len(N)
x
}
} else {
FUN <- function(N) rtree(N)$edge
}
}
Thus avoiding evaluating if
for each node with multichotomies.
Hi,
I found this somewhat strange behaviour of
multi2di()
. Depending on the parameterrandom
, the output may or may not be an ultrametric tree. I may be wrong (not really a specialist here), but my understanding was thatrandom
was essentially used to resolve multicotomies in random order vs. in the order they appeared in the tree, and should not change the nature of the tree. Is that correct?Reproducible example below (using a character string for convenience. Also works if you're reading the tree from a file):
Is this something that was expected to happen?
Cheers, Felipe