This post is a continuing exploration of UPGMA from a post the other day, using Python. To make it easy to visualize, the data are points in two dimensions, and the distances are euclidean.

The example code contains a Point class with a weight attribute, which is the number of points "contained" within it. The primary data points have weight 1, the combination of two primary points has weight 2, and so on.

The

`cluster`

function finds the two points that are the closest together, and averages them together, using the weights.The plot is shown above with the primary data points in blue. I added the arrows afterward to indicate which points have been averaged. You can clearly see the effect of weighting on points 'H' and 'I'.

One thing I'm puzzling about is the conflict between the weighting that I'm doing (as described by Felsenstein) and the U in the name UPGMA. I'll have to look into this to check if I'm really doing it correctly.

[UPDATE: Professor Felsenstein has an extensive comment to this post and notes that the method used here is

*not*UPGMA but another one. The problem is that I calculate the weighted average of (x,y) for a set of points and then compute the distance to the resulting virtual point. Although this is similar to the average of the distances when the targets lie roughly in the same direction, one can easily imagine a situation in which the results are wildly different (as he details).

I should modify this code to keep a list of its component points and do a real UPGMA calculation. I'll try to remember to do that. Thanks for reading!]

## 1 comment:

Just noticed your UPGMA post. I agree that the U in UPGMA, which stands for Unweighted, seems hard to reconcile with the use of weighted averages. I think Sokal and Sneath were thinking of it from the point of view of the species (or whatever the things being clustered are). The weights on groups give equal weight to each species within them.

I also wonder whether your diagram really shows what UPGMA does. When a pair of objects are clustered, the distance to the cluster is the average of the distances to its members. But your diagram shows the distance being to the average of the points in the cluster. Distance to averages aren't averages of distances. Consider two points, one a mile north of me, one a mile south of me. The distance to their average is zero (as the average is right on top of me), but the average of distances is 1 mile.

I think the clustering method your diagram describes is called Centroid Linkage, and is not the same as UPGMA.

Post a Comment