Statistics & probability

Hierarchical clustering dendrogram calculator from pairwise distances

Construct a deterministic agglomerative hierarchy from supplied pairwise dissimilarities and return its requested-height partition.

Your numbers

Symmetric, nonnegative, zero diagonal; row and column labels are their zero-based positions.
Different linkage definitions answer different cluster-distance questions.
Merges at height ≤ this value are included.

Calculated on your device. Your inputs aren’t sent to us.

Your result

Ready when you are

Enter your inputs and select Calculate.

Report an issue

Behind the numbers

How this calculation works

Construct a deterministic agglomerative hierarchy from supplied pairwise dissimilarities and return its requested-height partition.

THE FORMULAd_single(A,B)=min d(i,j); d_complete(A,B)=max d(i,j); d_average(A,B)=Σd(i,j)/(|A||B|).

A worked example

Average linkage joins default observations 0 and 1 at height 1, then 2 and 3 at height 2, and joins the two pairs at height 4. A cut at 2.5 gives two clusters.

Good to know

2–80 square symmetric nonnegative distance matrix with exact zero diagonal. Single, complete and unweighted pair-group average linkage; active cluster-ID tie rule and cut-at-≤ convention. No Ward on arbitrary dissimilarities, automatic correct cluster count or statistical significance.

A hierarchy records more than one partition

Hierarchical clustering builds nested groups by repeatedly merging the closest active clusters. Its linkage table records the complete sequence, allowing several cut heights to be examined without fitting a new hierarchy. A dendrogram is a compact representation of those merges, not a probability model for the labels of individual observations.

The input is a pairwise dissimilarity matrix rather than a feature table. This makes the choice of distance explicit and allows a non-Euclidean dissimilarity when the selected linkage accepts it. The output depends on that distance choice; changing how measurements were scaled before constructing distances can change the entire hierarchy.

Hierarchical clustering dendrogram calculator from pairwise distances worked exampleheight 4cut 2.5height 2height 10123
Scroll across to see the full diagram.
Average linkage joins default observations 0 and 1 at height 1, then 2 and 3 at height 2, and joins the two pairs at height 4. A cut at 2.5 gives two clusters.

Compare this with the Minimum cluster editing calculator with a clique partition. Build nested distance-based clusters and show all merge heights; graph cluster editing changes edges to minimize an integer disagreement count and produces a single partition.

Validate the supplied distance information

Use a square matrix whose row and column positions refer to the same observations in the same order. The diagonal must be zero, and a pair must have the same distance in either direction within the stated numerical symmetry tolerance. All off-diagonal values must be finite and nonnegative.

Zero distance between distinct observations is allowed and can represent duplicates under the chosen dissimilarity. It may create ties, so its interpretation should be documented. The page does not infer missing distances, symmetrize a directed travel-cost matrix or transform a similarity score into a distance without an explicit user decision.

Choose what distance between clusters means

Single linkage uses the closest member pair across two clusters. Complete linkage uses their farthest pair. Average linkage uses the mean distance across all cross-cluster member pairs, weighting each observation pair equally. These definitions can favor different shapes even when they begin with exactly the same matrix.

Average linkage here is the unweighted pair-group method at the observation level, often called UPGMA. It is not the method that gives two previously formed clusters equal weight regardless of their size. The named alternatives are kept on one page because they share the same input task while exposing a meaningful comparison in the same interface.

Track identifiers and deterministic ties

Original observations use identifiers zero through n minus one. Each merge creates a new cluster identifier, starting at n, and lists its two children, merge height and number of original members. Those records reconstruct the dendrogram without needing to infer membership from how a drawing happens to be arranged.

When distances tie exactly, the smallest pair of active cluster identifiers is selected. Another package may use a different deterministic tie rule and produce a different but equally admissible hierarchy at a tied height. Match the distance and tie conventions before treating a discrepancy in child order as an arithmetic failure.

Read the four-observation example

The default matrix has its smallest dissimilarity, one, between observations zero and one. Observations two and three have distance two and merge next. For average linkage, the four cross-pair distances between those groups are four, five, three and four, so their average is four.

A cut at 2.5 therefore includes the first two merges and excludes the merge at four. The returned partition is the pair zero-one and the pair two-three. The threshold rule includes equality, so a cut exactly at a merge height places the children of that merge in the same cluster.

Separate descriptive groups from decisions

A dendrogram always provides a nesting for valid input, including data with no scientifically meaningful group separation. A visually large gap between merge heights may motivate further investigation, but this page does not attach a p-value or automatically choose the correct number of clusters from that gap.

The supplied cut height is an analysis decision in the same units as the dissimilarity. If the matrix contains a mix of incompatible units or scales, a precise merge sequence can still be misleading. Selecting a linkage and cutoff should follow the purpose of the analysis rather than treating the default choice as universally suitable.

Scope, checks and reproducibility

Ward linkage is deliberately excluded because its variance interpretation requires additional Euclidean structure and conventions that an arbitrary distance matrix need not satisfy. Missing values, directed dissimilarities, automatic standardization and bootstrap stability are also outside the calculation. The three supported methods all use the entered pairwise values directly.

Independent checks can recompute each reported merge distance from the original member pairs and verify that the final cluster contains every observation once. Increasing the cut height cannot split an existing group under these methods. Renaming labels consistently changes names only, although a tied hierarchy may legitimately reflect the documented identifier-based tie rule.

A few questions, answered

Can I enter similarities?

Only after explicitly converting them to meaningful nonnegative dissimilarities; the page does not guess a conversion.

What is the average linkage convention?

It averages all original observation-pair distances across the two clusters, corresponding to UPGMA rather than equal weighting of existing clusters.

Does the cut include a merge at the exact threshold?

Yes. Merges with height less than or equal to the entered cut are included.

Why is Ward linkage absent?

Arbitrary supplied dissimilarities need not satisfy the Euclidean conditions required for Ward’s variance interpretation.

Find your calculator

Start typing to explore the library.