Learn R Programming

GAPR (version 0.1.0)

hctree_sort: HCTree Sort

Description

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.

Usage

hctree_sort(distance_matrix, externalOrder = NULL, orderType, flipType)

Value

A list representing a dendrogram tree structure, containing: left, right, and height for tree construction, and order for the optimal leaf order.

Arguments

distance_matrix

A square numeric proximity matrix (either n × n or p × p) representing pairwise distances between items.

externalOrder

An integer vector specifying an initial or external ordering of the items (can be empty or NULL if not used).

orderType

An integer indicating the type of hierarchical clustering order to apply.

flipType

An integer indicating the flipping methods.

Details

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.