A thin, deterministic wrapper around stats::hclust() + stats::cutree()
that cuts an agglomerative hierarchical clustering into k groups. It is a
pure function of x (no randomness, no global RNG use), which makes it a
valid black-box clustering routine to pass to
selective_hotelling_bc() (the package's preferred, exact selective test for
arbitrary clustering algorithms).
By default the tree is built on squared Euclidean distances
(stats::dist(x)^2), matching the clusterpval / KmeansInference
selective-conditioning convention; set square = FALSE for ordinary
Euclidean distances.
Unlike kmeans_fun(), the returned object deliberately carries no
init_centers_idx field: hierarchical clustering has no random initialization
to condition on, so it should be treated as a pure black box and never
re-seeded.
Arguments
- x
A numeric \(n \times p\) data matrix with observations in rows.
- k
Number of clusters to cut the dendrogram into.
- method
Agglomeration method passed to
stats::hclust()(e.g."average","single","complete","ward.D2").- square
If
TRUE(default) the dendrogram is built on squared Euclidean distances (stats::dist(x)^2, theclusterpvalconvention); ifFALSE, ordinary Euclidean distances (stats::dist(x)) are used.
Value
A list with elements:
clusterAn integer vector of length
nrow(x)of cluster labels in1:k(fromstats::cutree()).trajectoryA length-1 list,
list(cluster). Hierarchical clustering has no Lloyd iterations, so the "trajectory" is a single (final) assignment vector.
The object intentionally does not include an init_centers_idx field.
