Skip to contents

Validates a precomputed hierarchical clustering object hcl and/or distance object dismat against the data matrix X, infers or validates the linkage criterion, and checks that clusters is a valid specification. Also discards precomputed hcl and dismat when sample splitting is requested (since X changes after splitting), and reconciles sample_split with return_X_clus.

Usage

validate_hc_setting(
  hcl,
  dismat,
  X,
  NC,
  clusters,
  linkage,
  linkage_missing,
  sample_split,
  return_X_clus
)

Arguments

hcl

An optional precomputed hierarchical clustering object of class "hclust", as returned by fastcluster::hclust() or stats::hclust(), or NULL.

dismat

An optional precomputed squared Euclidean distance object of class "dist", as returned by stats::dist(X, method = "euclidean")^2, or NULL.

X

An \(n \times p\) data matrix.

NC

Integer. Number of clusters in the partition obtained by cutting the hierarchical clustering tree.

clusters

Integer vector of length 2 containing the labels of the two clusters to compare. Entries must belong to 1:NC.

linkage

Character string specifying the linkage criterion used in hierarchical clustering. Ignored (and overridden) when hcl is provided.

linkage_missing

Logical. Whether linkage was left at its default (i.e., missing(linkage) in the calling function), used to decide whether to warn about a mismatch with hcl$method.

sample_split

Logical. Whether sample splitting is used to estimate Sigma.

return_X_clus

Logical. Whether the data matrix used for clustering should be returned.

Value

A named list with:

hcl

The validated hcl, or NULL if it was not provided or was discarded because sample_split = TRUE.

dismat

The validated dismat, or NULL if it was not provided or was discarded because sample_split = TRUE.

linkage

The validated (or hcl-inferred) linkage criterion.

return_X_clus

The (possibly adjusted) return_X_clus flag.