skbio.tree.TreeNode.compare_tip_distances

TreeNode.compare_tip_distances(other, sample=None, dist_f=<function distance_from_r at 0x2ab663ae0b90>, shuffle_f=<built-in method shuffle of mtrand.RandomState object at 0x2ab64d54a8e8>)[source]

Compares self to other using tip-to-tip distance matrices.

Value returned is dist_f(m1, m2) for the two matrices. Default is to use the Pearson correlation coefficient, with +1 giving a distance of 0 and -1 giving a distance of +1 (the maximum possible value). Depending on the application, you might instead want to use distance_from_r_squared, which counts correlations of both +1 and -1 as identical (0 distance).

Note: automatically strips out the names that don’t match (this is necessary for this method because the distance between non-matching names and matching names is undefined in the tree where they don’t match, and because we need to reorder the names in the two trees to match up the distance matrices).

Parameters:

other : TreeNode

The tree to compare

sample : int or None

Randomly subsample the tips in common between the trees to compare. This is useful when comparing very large trees.

dist_f : function

The distance function used to compare two the tip-tip distance matrices

shuffle_f : function

The shuffling function used if sample is not None

Returns:

float

The distance between the trees

Raises:

ValueError

A ValueError is raised if there does not exist common tips between the trees

Examples

>>> from six import StringIO
>>> from skbio import TreeNode
>>> # note, only three common taxa between the trees
>>> tree1 = TreeNode.read(StringIO("((a:1,b:1):2,(c:0.5,X:0.7):3);"))
>>> tree2 = TreeNode.read(StringIO("(((a:1,b:1,Y:1):2,c:3):1,Z:4);"))
>>> dist = tree1.compare_tip_distances(tree2)
>>> print("%.9f" % dist)
0.000133446