Closed cwbcm closed 1 month ago
Hi @cwbcm,
it is a feature
, but it should be documented better.
The phyDat
object stores site patterns only once avoiding unnecessary computations, but has usually two additional attributes weight
and index
:
weight <- attr(Laurasiatherian, "weight")
index <- attr(Laurasiatherian, "index")
storing the weight and position of each site pattern.
Hi,
Thank you for making this great package! I am trying to compute parsimony for a list of traits using the parsimony() function. I found that the overall parsimony score doesn't match the sum of by site parsimony score.
library(phangorn) set.seed(3) data(Laurasiatherian) dm <- dist.hamming(Laurasiatherian) tree <- NJ(dm) # compute overall parsimony and by site parsimony parsimony(tree, Laurasiatherian) parsimony(tree, Laurasiatherian, site = "site") |> sum()
So you could do either
> (parsimony(tree, Laurasiatherian, site = "site") * weight) |> sum()
[1] 9796
or
> parsimony(tree, Laurasiatherian, site = "site")[index] |> sum()
[1] 9796
Kind regards, Klaus
Hi Klaus,
Thank you so much for the clarification!
Thanks, Chen
Hi,
Thank you for making this great package! I am trying to compute parsimony for a list of traits using the parsimony() function. I found that the overall parsimony score doesn't match the sum of by site parsimony score.
Here is the output
When I dig deeper, I found that duplicated traits are not computed with the site="site" option.
When computing overall parsimony, both sites are included. But only one parsimony score is returned when using the site = "site" option.
I am not sure if this is an intended feature or a bug.
Here is my session info