Skip to content

What is hierarchical clustering? Methods, linkage and a worked example

Hierarchical clustering is a method that groups similar cases, such as survey respondents, by repeatedly merging the two closest groups (agglomerative) or splitting one large group (divisive). The result is a tree called a dendrogram. You choose the number of clusters afterward by cutting the tree at a height that suits your data.

Tracey Stuart
Tracey Stuart

Global VP Analysis & Insights · Updated December 29, 2025

Part of the guide 3 Types of Factor Analysis
Dendrogram of US states built with Ward linkage, with four colored boxes marking the clusters left after cutting the tree

You have survey answers from a few thousand respondents and suspect they fall into a handful of types, but you do not know how many or what separates them. Hierarchical clustering is one way to find out. It is one of the techniques in our guide to factor analysis, PCA and cluster analysis in market research, and this article shows how it works and how to use it on survey data.

Key takeaways

  • Hierarchical clustering groups similar respondents by repeatedly merging the two closest groups, producing a tree called a dendrogram that you cut to choose the number of clusters.
  • Standardize variables before clustering, because a 0 to 10 question spreads wider than a 1 to 5 question and will otherwise dominate the distances.
  • Linkage method shapes the tree: single linkage chains, complete linkage forms compact groups, and Ward linkage, a common starting point for survey work, gives tight, similar-sized clusters.
  • Cut the dendrogram just below a long vertical gap, check that clusters are large enough to matter, and keep only groups you can describe in one sentence.
  • Unlike k-means, which needs the number of clusters set before the run, hierarchical clustering lets you choose it afterward but gets costly on very large samples.

How does hierarchical clustering work?

Hierarchical clustering builds a family tree of your cases. Each respondent starts alone, the most similar are joined, and the process repeats until everyone sits in one group:

  1. Choose the variables to cluster on and put them on a common scale.
  2. Calculate the distance between every pair of respondents.
  3. Treat each respondent as a cluster of one.
  4. Merge the two closest clusters.
  5. Recalculate the distance from the new cluster to the others, using a linkage rule (below).
  6. Repeat steps 4 and 5 until one cluster remains, recording each merge distance.
  7. Draw the tree, called a dendrogram, and decide where to cut it.

What is the difference between agglomerative and divisive clustering?

Agglomerative clustering works bottom-up: every case starts as its own cluster and the closest pair is merged at each step. Divisive clustering works top-down: it starts with one cluster holding everyone and splits it, then splits the pieces, until each case stands alone.

Tree diagram of agglomerative clustering: eight single points, a to h, are merged step by step from the bottom up into one cluster

Tree diagram of divisive clustering: one cluster holding all eight points is split step by step from the top down until each point stands alone

Agglomerative is the one you will meet. A divisive method must consider every way of splitting a cluster in two, and for n cases there are 2^(n-1) - 1 splits: 15 for 5 cases, over 536 million for 30. Divisive methods therefore rely on shortcuts.

Which distance measure should you use?

A distance measure turns two respondents’ answers into one number; bigger means less alike. Three are common.

  • Euclidean distance is the straight-line distance: square the difference on each variable, add them up, and take the square root. It suits rating scales and is the one Ward’s method requires.
  • Manhattan distance adds up the absolute differences instead, so one large gap on a single question pulls it less.
  • Cosine distance compares the pattern of answers rather than their size. It suits text counts and profiles where one person rates everything higher.

Whichever you choose, standardize first. A 0–10 question spreads wider than a 1–5 question and will dominate the distances unless you convert each variable to z-scores.

How do the linkage methods differ?

Once clusters hold more than one case, you need a rule for the distance between two clusters. That rule is the linkage method, and it shapes the tree more than most people expect.

MethodDistance between two clustersTypical behavior
SingleClosest pair of cases, one from each clusterChains: joins clusters through a thin bridge of points
CompleteFarthest pair of casesCompact groups; sensitive to outliers
AverageMean of all pairwise distances between the two clustersA compromise between single and complete
WardMerges the pair that least increases the total within-cluster varianceTight, similar-sized, roughly round groups; needs Euclidean distance

Many analysts start with Ward or average linkage for survey work.

What does a worked example look like?

Take five respondents scored 0–10 on price sensitivity (x) and brand loyalty (y), as (x, y): A (1, 2), B (2, 2), C (5, 6), D (8, 6) and E (8, 8). The numbers are illustrative.

Euclidean distance between A and B is the square root of (2 - 1)² + (2 - 2)², which is 1. D to E is the square root of 0² + 2², which is 2.

C to D is 3. C to E is the square root of 3² + 2², or 3.61. B to C is the square root of 3² + 4², or 5.

Now merge:

StepMergesinglecompleteaverage
1A and B (closest pair, distance 1)1.001.001.00
2D and E (next closest, distance 2)2.002.002.00
3C joins D and E3.00 (C–D)3.61 (C–E)3.30
4A,B joins C,D,E5.00 (B–C)9.22 (A–E)7.27

C could have joined A,B instead, but it is at least 5.00 from them, so D,E wins under every linkage. The step 3 average is (3.00 + 3.61) / 2 = 3.30. The step 4 average is the mean of six distances: (5.66 + 5.00 + 8.06 + 7.21 + 9.22 + 8.49) / 6 = 7.27.

Ward’s method gives the same order. Each merge costs n1 × n2 / (n1 + n2) times the squared distance between cluster centers: 0.50, 2.00, 6.67 and 62.43, which sum to 71.60, the total squared spread of the points around their mean.

How do you read a dendrogram and choose where to cut?

In a dendrogram, each case is a leaf along the bottom and the vertical axis is the distance at which branches join. Read heights, not horizontal positions. Branches can be flipped without changing the tree, so neighboring leaves are not necessarily similar.

To get clusters, draw a horizontal line across the tree. The number of vertical lines it crosses is the number of clusters. In our example, a cut at 2.5 gives three clusters (A,B; C; D,E). A cut anywhere between 3.30 and 7.27 gives two (A,B and C,D,E) under average linkage, and the long gap before the final merge suggests two groups.

Real data is messier, so combine three checks.

  • Look for a long vertical gap before a merge, and cut just below it.
  • Check cluster sizes. Four people in a sample of 2,000 are probably outliers, not a segment.
  • Ask whether you can describe each group in one sentence.

How does hierarchical clustering compare with k-means?

K-means places k centers, assigns each respondent to the nearest, moves the centers, and repeats.

QuestionHierarchicalK-means
Number of clustersChosen after, by cutting the treeSet before the run
OutputA nested treeOne flat set of groups
RepeatabilitySame result for the same data and settingsDepends on starting centers; run several starts
Sample sizeNeeds every pairwise distance, so cost grows with the square of the sampleHandles large samples easily

A common workflow is to cluster a sample hierarchically to see how many groups the data supports, then run k-means on the full sample with that k.

How do you use hierarchical clustering for survey segmentation?

  1. Pick the inputs. Use attitudes, needs or behaviors; keep demographics for describing segments. If you have dozens of correlated rating items, reduce them first with principal component analysis or factor scores, as covered in practical uses of factor analysis.
  2. Clean and scale. Handle missing answers, remove straight-liners who gave the same answer to every item, and standardize.
  3. Run Ward linkage on Euclidean distance and study the dendrogram. Shortlist candidate solutions, for example four, five and six segments.
  4. Profile each solution. Cross-tabulate segment membership against the clustering variables, demographics, purchase intent and usage. Once each respondent carries a segment label, Halo Reports can profile it with crosstabs and banner tables that include weighting and significance testing, plus charts and interactive report pages. Wide, complex studies fit one governed platform for insights and research teams.
  5. Test stability. Re-run on a random half of the sample and with a second linkage method. Segments that keep reappearing are more trustworthy.
  6. Choose the solution you can act on. Each segment should be large enough to matter and different in a way that changes what you would do.

What are the common mistakes with hierarchical clustering?

  • Skipping standardization. The widest-ranging variable quietly decides the result.
  • Using single linkage on noisy data. You get one giant cluster plus a trail of single respondents.
  • Treating the output as proof. Clustering returns groups even for random data. Check stability and interpretability.
  • Running it on a very large sample. Cluster a subsample first.
  • Using it where it does not fit. It is the wrong tool for plain categorical data without a suitable distance, or when you already know the groups and want to predict membership.

To try it, take a survey you already have, choose six to ten attitude questions, standardize them and run Ward linkage on a random sample of a few hundred respondents. Cut the tree at two heights and see which solution you can describe in a sentence per segment. For brand segments, track brand health, consideration and competitors continuously.

Frequently asked questions

Is hierarchical clustering supervised or unsupervised?

Unsupervised. There is no outcome variable to predict and no labeled examples. The algorithm forms groups only from how similar the cases are on the variables you give it, so you must judge whether the groups mean anything.

Can you use hierarchical clustering on categorical survey data?

Yes, but not with plain Euclidean distance on category codes. Use a distance built for the data type, such as Gower distance for mixed variables or Jaccard distance for yes/no items, then apply any linkage method that accepts a custom distance matrix.

How do you check that a dendrogram fits the data?

Compute the cophenetic correlation: the correlation between the original pairwise distances and the distances implied by the tree (the height at which each pair first joins). Values near 1 mean the tree preserves the original distances well.

How is cluster analysis different from factor analysis?

Cluster analysis groups cases, usually respondents, into segments. Factor analysis groups variables, usually survey questions, into a smaller number of underlying dimensions. Analysts often use factor scores as the inputs to a respondent clustering.

See how insights teams do this in mTab.

Bring one tracker or study. We'll build the tables and the report before we meet.

Book a demo