# How does “ward” clustering (in R's hclust function) work?

A simple example:

plot(hclust(dist(c(1:3)),method = "ward"))

I would like to know which calculations (in R) can reproduce the distance of 3 from {1,2} to be 1.67 Thanks.

• As far as I know this height is more-less arbitrary measure of "joining penalty" and thus does not correspond to any interpretable distance... – user88 Aug 3 '11 at 22:44
• Hi mbq. I am searching to understand the joining penalty. Thanks. – Tal Galili Aug 6 '11 at 7:26

The distance between two clusters is calculated using the Lance-Williams update formula, see the Wikipedia entry. It holds that: $$2/3*\text{abs}(2-3)+2/3*\text{abs}(1-3)-1/3*1 = 1.666667$$

• nice, I see it is a new entry to Wikipedia. Thanks. – Tal Galili May 12 '13 at 19:56

It is in fact (in words) the absolute distance from the extreme value to the overall mean, plus two times the absolute distance from the mean of the two moderate values to the overall mean, minus a third of the absolute distance from one of the moderate values to mean of the two moderate values, minus a third of the absolute distance from the other moderate value to the mean of the two moderate values.

Try this with

plot(hclust(dist(c(0,18,126)),method = "ward"))


and the absolute distance from 126 to 48, plus twice the absolute distance from 9 to 48, minus a third of the absolute distance from 18 to 9, minus a third of the absolute distance from 0 to 9, gives $78 + 2\times 39 - 9/3 -9/3 =150$.

• Thanks Henry. x <- c(0,18,126) abs(max(x) - mean(x)) + 2* abs(mean(x) - mean(x[1:2])) - 1/3 * abs(x - mean(x[1:2])) - 1/3 * abs(x - mean(x[1:2])) Do you have any reference you would suggest for understanding the logic behind this? – Tal Galili Aug 4 '11 at 19:03
• Not really. You could look up "Ward's minimum distance method" or look at this which says "One can compute the square roots of the fusion distances ... and draw the dendrogram accordingly. This solution ... is most often used in computer programs and functions, including hclust() of STATS and agnes() of CLUSTER in R; it removes the distortions created by squaring the distances." – Henry Aug 4 '11 at 19:17
• I think the idea may be that the height is the sum of the distances between the old means and the new means weighted for the number of elements, less an adjustment for the heights of the earlier subsets to take account of new elements being introduced. But this is my pattern recognition rather than knowledge. – Henry Aug 4 '11 at 19:20