Hierarchical cluster analysis of observations, with an example
Cluster analysis of observations groups items, such as machines, lots, suppliers or parts, so that items in the same group are similar on several measurements and items in different groups are not. Hierarchical agglomerative clustering starts with every item as its own cluster and joins the two closest clusters at each step until one cluster remains. The record of those joins, drawn as a dendrogram, lets you choose how many groups to keep.
When to use it
- You have several measurements on each of a set of machines, tools, lots or sites and want to see which behave alike.
- You want to group items for a decision: maintenance plans, supplier tiers, product families, test coverage.
- You do not know the groups in advance. If you do, and want a rule to assign new items, use discriminant analysis.
- The number of items is modest (up to a few hundred), so a tree of joins is readable.
How it works
1. Standardize. If the variables are in different units, convert each to z = (x − x̄)/s so that no variable dominates just because of its unit.
2. Measure distance. The usual choice is Euclidean distance between standardized items. Others include Manhattan distance and squared Euclidean.
3. Choose a linkage, the rule for the distance between two clusters:
- Single linkage: the closest pair of members. Tends to form long chains.
- Complete linkage: the farthest pair. Gives compact clusters of similar size.
- Average linkage: the average of all pairwise distances. A common compromise, used in this example.
- Ward's method: joins the pair that least increases the total within-cluster sum of squares. Gives compact, even clusters.
4. Join step by step. At each step, join the two closest clusters and record the distance at which they joined. Some programs also report a similarity level, 100 × (1 − d / d_max), where d_max is the largest distance between any two items.
5. Cut the tree. Look for a large jump in the joining distance. Stopping just before the jump gives clusters that are tight inside and far apart.
Example
An extrusion plant runs eight dies for the same profile. To plan maintenance, the engineer summarizes each die over the last month by its average wall-thickness deviation, surface roughness and output rate:
| Die | Wall deviation (mm) | Roughness Ra (µm) | Output (kg/h) |
|---|---|---|---|
| D1 | 0.046 | 0.92 | 413 |
| D2 | 0.079 | 1.18 | 448 |
| D3 | 0.021 | 1.07 | 424 |
| D4 | 0.113 | 1.75 | 376 |
| D5 | 0.052 | 0.72 | 405 |
| D6 | 0.082 | 0.97 | 465 |
| D7 | 0.082 | 1.15 | 460 |
| D8 | 0.116 | 1.48 | 385 |
Each variable is standardized (means 0.0739 mm, 1.155 µm and 422.0 kg/h; standard deviations 0.0328 mm, 0.327 µm and 33.4 kg/h). With Euclidean distance and average linkage, the joins are:
| Step | Joined | Distance | Clusters left |
|---|---|---|---|
| 1 | D2 + D7 | 0.382 | 7 |
| 2 | D1 + D5 | 0.683 | 6 |
| 3 | (D2, D7) + D6 | 0.698 | 5 |
| 4 | D4 + D8 | 0.874 | 4 |
| 5 | (D1, D5) + D3 | 1.244 | 3 |
| 6 | (D1, D3, D5) + (D2, D6, D7) | 2.041 | 2 |
| 7 | all | 3.193 | 1 |
The distance climbs slowly to 1.244 and then jumps to 2.041. Stopping at three clusters:
| Cluster | Dies | Wall deviation | Roughness | Output |
|---|---|---|---|---|
| 1 | D1, D3, D5 | 0.040 mm | 0.90 µm | 414 kg/h |
| 2 | D2, D6, D7 | 0.081 mm | 1.10 µm | 458 kg/h |
| 3 | D4, D8 | 0.115 mm | 1.62 µm | 381 kg/h |
Cluster 1 holds accurate, smooth dies at normal output. Cluster 2 runs faster but with more wall deviation, likely a speed setting worth reviewing. Cluster 3 is worse on all three measures: the worn dies, first in line for refurbishment. Complete and single linkage give the same three clusters on these data, which adds confidence.
How to read the results
- Look for the big jump in joining distance. It marks the natural number of clusters.
- Profile each cluster in original units. Means of each variable per cluster turn the grouping into an engineering story.
- Check stability. Rerun with another linkage or distance. Clusters that survive the change are real; those that do not are fragile.
- Remember that clustering always finds clusters. Even random data produce a tree. Ask whether the groups make physical sense.
Common mistakes
- Clustering unstandardized data. Output in kg/h, with values in the hundreds, would decide the clusters alone.
- Choosing the number of clusters before looking. Let the joining distances and the meaning of the groups guide you.
- Including redundant variables. Three nearly identical roughness measures count roughness three times. Use variable clustering or principal components first.
- Trusting single linkage blindly. It can chain dissimilar items together through a series of close neighbors.
Frequently asked questions
What is a dendrogram?
A tree diagram of the joins: items along one axis, joining distance (or similarity) along the other. Each join is a bar at the height where two clusters merged. Cutting the tree at a height gives the clusters.
Which linkage should I use?
Average linkage and Ward's method are good defaults. Use complete linkage for compact, similarly sized groups. Avoid single linkage unless you are looking for chains or outliers.
How is this different from k-means?
K-means needs the number of clusters in advance and moves items between clusters to minimize within-cluster spread. Hierarchical clustering builds the whole tree, so you can choose the number afterwards, but an item cannot change cluster once joined.
Can I cluster observations with categorical variables?
Not with Euclidean distance. Use a distance designed for mixed data, such as Gower's distance, or recode the categories carefully.