Thursday, December 8, 2011

Minor fix to anc.ML()

Dave Bapst kindly pointed out that the function anc.ML() will fail if there are any zero length internal or terminal branches in the tree.

For zero length tip edges this is unavoidable because the determinant of vcvPhylo(tree) for this tree will always be zero. However, for zero length internal edges this can be avoided by first collapsing these using the ape function di2multi(). Unfortunately, anc.ML could not handle these trees because it uses pic() to estimate a starting value for the evolutionary rate, σ2!

Fortunately, I have resolved this by way of a couple of fixes. 1) The function first checks if the tree contains any zero length edges. If it does, then anc.ML will return an informative error message. 2) If the tree does contain polytomies, then pic() will be called on an arbitrarily resolved tree (using multi2di). The new version of this function is available here.


  1. BTW for zero length terminal edges it is probably reasonable to just add a very small length to that edge. For many comparative analyses, this is inadvisable, but for ancestral state estimation it is probably OK since it will basically just force the internal node to have an estimated state equal to the tip state (which makes sense if zero evolutionary distance separates the tip from the internal node from which it descends).

  2. Thanks for the fix, Liam!

    I feel like many people add "very small lengths" as a quick fix, particularly in paleo-tree analyses. It seems there has been very little work looking in general at how this correction affects comparative analyses.


  3. Yes, this is a common practice that, as I said, is generally ill-advised. For ancestral character estimation if the terminal state is known without error and the terminal edge is (truly, not as an artifact of our method for phylogeny inference) very short, then it should be OK. - Liam