LingPy

This documentation is for version 2.0.dev, which is not released yet.

lingpy.algorithm.cython._cluster.flat_upgma

lingpy.algorithm.cython._cluster.flat_upgma(threshold, matrix, taxa=[], revert=False)

Carry out a flat cluster analysis based on the UPGMA algorithm (Sokal1958).

Parameters :

threshold : float

The threshold which terminates the algorithm.

matrix : or numpy.array

A two-dimensional containing the distances.

taxa : (default = [])

A containing the names of the taxa. If the is left empty, the indices of the taxa will be returned instead of their names.

Returns :

clusters : dict

A dictionary with cluster-IDs as keys and a of the taxa corresponding to the respective ID as values.

See also

lingpy.algorithm.clusters.upgma, lingpy.algorithm.clusters.neighbor

Examples

The function is automatically imported along with LingPy.

>>> from lingpy import *

Create a of arbitrary taxa.

>>> taxa = ['German','Swedish','Icelandic','English','Dutch']

Create an arbitrary distance matrix.

>>> matrix = squareform([0.5,0.67,0.8,0.2,0.4,0.7,0.6,0.8,0.8,0.3])
>>> matrix
array([[ 0.  ,  0.5 ,  0.67,  0.8 ,  0.2 ],
       [ 0.5 ,  0.  ,  0.4 ,  0.7 ,  0.6 ],
       [ 0.67,  0.4 ,  0.  ,  0.8 ,  0.8 ],
       [ 0.8 ,  0.7 ,  0.8 ,  0.  ,  0.3 ],
       [ 0.2 ,  0.6 ,  0.8 ,  0.3 ,  0.  ]])

Carry out the flat cluster analysis.

>>> flat_upgma(0.5,matrix,taxa)
{0: ['German', 'Dutch', 'English'], 1: ['Swedish', 'Icelandic']}

This Page