This function applies a hierarchical clustering tree (HCT) sorting algorithm to reorder rows of a proximity matrix. It supports external ordering constraints, different linkage-based order types, and optional flipping for optimal layout.
hctree_sort(distance_matrix, externalOrder = NULL, orderType, flipType)
A list representing a dendrogram tree structure, containing:
left
, right
, and height
for tree construction,
and order
for the optimal leaf order.
A square numeric proximity matrix (either n × n or p × p) representing pairwise distances between items.
An integer vector specifying an initial or external ordering of the items (can be empty or NULL if not used).
An integer indicating the type of hierarchical clustering order to apply.
An integer indicating the flipping methods.
distance_matrix
The input matrix must represent pairwise distances between items.
If you start with a similarity matrix (e.g., a correlation matrix), you must convert it to a dissimilarity matrix before use.
For example, for correlation-based similarities,
use as.matrix(as.dist(1 - cor_matrix))
or other appropriate transformations to convert it to a proper distance matrix.
The matrix should also be symmetric and non-negative.
orderType
Specifies the linkage method used for hierarchical clustering:
0
: Single-linkage
1
: Complete-linkage
2
: Average-linkage (UPGMA)
flipType
Controls how the branches of the clustering tree are flipped:
1
: Flip based on externalOrder
This option should be used only when externalOrder
is provided.
2
: Uncle-flipping
3
: Grandpa-flipping
Important:
Do not specify both flipType = 1
and a NULL
or missing externalOrder
.
When using flipType = 1
, externalOrder
must be a valid integer vector.
Please refer to computeProximity
for complete usage examples.