Statistical Methods
Recover a Fixed Number of Groups from a Linkage Record
Define the task
A linkage record describes successive merges of clusters. Cutting after a chosen number of merges recovers a requested number of groups and is different from drawing a visually convenient line on a dendrogram. The teaching tool accepts a complete binary linkage record and a target count. It uses merge order rather than a height cutoff, so tied heights do not create ambiguity about how many merges are applied. Choosing the count remains an analysis decision.
Carry out the check
Label original observations 0 through n−1. At merge i, the new cluster receives index n+i. Validate that both children exist, differ and have not already been consumed by another merge. Check the recorded membership count against the children's actual total. To retain k clusters, apply the first n−k merges, then list memberships in original observation order. Group labels are arbitrary; compare partitions by membership. A fixed-count cut does not establish that the clusters are stable or scientifically distinct.
Worked hypothetical example
For four hypothetical observations, merge rows (0,1,1,2),(2,3,2,2),(4,5,5,4) create two pairs and then combine them. A two-cluster cut yields memberships {0,1} and {2,3}; a three-cluster cut merges only {0,1}. Heights are recorded but not used by this count-based operation. A height-based cut has additional ultrametric requirements in the primary documentation. Preserve the distance metric, linkage method and chosen cut rule with exported labels so the analysis can be reproduced.
Method checked 21 November 2026 against Primary method documentation: cut_tree.