[R-sig-phylo] The Curious Behavior of is.binary.tree

2014-01-15 Thread David Bapst
Hi Emmanuel and the rest of the list,

In some code, I use the ape function is.binary.tree to test if a
phylogeny is fully dichotomous. However, some recent analyses have
made me wonder if this wasn't the right choice. I'm not sure if the
following is a bug report me or me not understand the reasoning of a
function in ape.

You see, I had an 'unrooted' (in ape terminology) tree with a basal
trichotomy. I wouldn't consider such a tree to be fully dichotomous,
but is.binary.tree says such a tree is in fact binary (i.e. returns
TRUE). It appears to be limited to just trees with basal trichotomies.
If the root is an even larger polytomy (more than three descendant
nodes), is.binary.tree returns FALSE.

I was a bit surprised, as the function description says This function
tests whether a phylogenetic tree is binary, i.e. whether every node
(including the root node) has exactly two descendant nodes. This
would make me think it also tests if the root has two descendant
nodes, but that doesn't seem to be the case, unless an unrooted tree
with three lineages is (for some reason I'm unaware of) considered to
have two descendant nodes.

There's also some stuff in ?is.binary.tree about fully dichotomous
trees having 2Ntip-2 edges, which is only true if the root is also
dichotomous (and thus the tree is 'rooted'). It isn't true for taxa
with a basal trichotomy.

Here's some code. I got the same results with both ape v3.0-11 and the
v3.1 that Emmanuel had sent out two weeks ago.

library(ape)

tree-rtree(10)
#collapse root
tree$edge.length[which(tree$edge[,1]==11)[1]]-0
tree1-di2multi(tree)
is.binary.tree(tree1)
is.rooted(tree1)

tree-stree(3)
is.binary.tree(tree)
is.rooted(tree)

tree-stree(4)
is.binary.tree(tree)
is.rooted(tree)

Is.rooted correctly returns FALSE, so does that mean best practice to
get a tree where every node has two descendant nodes would be use
is.binary.tree()  is.rooted()?

Curious on your thoughts on this and the intent of is.binary.tree.

-Dave

-- 
David W. Bapst, PhD
Adjunct Asst. Professor, Geology and Geol. Eng.
South Dakota School of Mines and Technology
501 E. St. Joseph
Rapid City, SD 57701

http://webpages.sdsmt.edu/~dbapst/
http://cran.r-project.org/web/packages/paleotree/index.html

___
R-sig-phylo mailing list - R-sig-phylo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo
Searchable archive at http://www.mail-archive.com/r-sig-phylo@r-project.org/


Re: [R-sig-phylo] The Curious Behavior of is.binary.tree

2014-01-15 Thread Liam J. Revell

Hi David.

In an unrooted, fully dichotomous tree each internal node is attached to 
three  exactly three nodes (some of which are tips). (In a rooted 
binary tree one additional internal node exists, the root, which is 
attached to only two nodes.) Ancestor  descendant have no meaning until 
the tree is rooted. The fact that an unrooted tree stored as an object 
of class phylo has one node with three 'descendants' (these aren't 
actually all descendants, as the tree is unrooted) is just an artifact 
of the way the object is stored in memory  thus is.binary.tree is 
behaving correctly.


All the best, Liam

Liam J. Revell, Assistant Professor of Biology
University of Massachusetts Boston
web: http://faculty.umb.edu/liam.revell/
email: liam.rev...@umb.edu
blog: http://blog.phytools.org

On 1/15/2014 3:34 PM, David Bapst wrote:

Hi Emmanuel and the rest of the list,

In some code, I use the ape function is.binary.tree to test if a
phylogeny is fully dichotomous. However, some recent analyses have
made me wonder if this wasn't the right choice. I'm not sure if the
following is a bug report me or me not understand the reasoning of a
function in ape.

You see, I had an 'unrooted' (in ape terminology) tree with a basal
trichotomy. I wouldn't consider such a tree to be fully dichotomous,
but is.binary.tree says such a tree is in fact binary (i.e. returns
TRUE). It appears to be limited to just trees with basal trichotomies.
If the root is an even larger polytomy (more than three descendant
nodes), is.binary.tree returns FALSE.

I was a bit surprised, as the function description says This function
tests whether a phylogenetic tree is binary, i.e. whether every node
(including the root node) has exactly two descendant nodes. This
would make me think it also tests if the root has two descendant
nodes, but that doesn't seem to be the case, unless an unrooted tree
with three lineages is (for some reason I'm unaware of) considered to
have two descendant nodes.

There's also some stuff in ?is.binary.tree about fully dichotomous
trees having 2Ntip-2 edges, which is only true if the root is also
dichotomous (and thus the tree is 'rooted'). It isn't true for taxa
with a basal trichotomy.

Here's some code. I got the same results with both ape v3.0-11 and the
v3.1 that Emmanuel had sent out two weeks ago.

library(ape)

tree-rtree(10)
#collapse root
tree$edge.length[which(tree$edge[,1]==11)[1]]-0
tree1-di2multi(tree)
is.binary.tree(tree1)
is.rooted(tree1)

tree-stree(3)
is.binary.tree(tree)
is.rooted(tree)

tree-stree(4)
is.binary.tree(tree)
is.rooted(tree)

Is.rooted correctly returns FALSE, so does that mean best practice to
get a tree where every node has two descendant nodes would be use
is.binary.tree()  is.rooted()?

Curious on your thoughts on this and the intent of is.binary.tree.

-Dave



___
R-sig-phylo mailing list - R-sig-phylo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo
Searchable archive at http://www.mail-archive.com/r-sig-phylo@r-project.org/