HclustParam-class: Hierarchical clustering

HclustParam-classR Documentation

Hierarchical clustering

Description

Run the base hclust function on a distance matrix within clusterRows.

Usage

HclustParam(
  clust.fun = NULL,
  metric = NULL,
  dist.fun = NULL,
  method = NULL,
  cut.fun = NULL,
  cut.dynamic = FALSE,
  cut.height = NULL,
  cut.number = NULL,
  cut.params = list(),
  ...
)

## S4 method for signature 'ANY,HclustParam'
clusterRows(x, BLUSPARAM, full = FALSE)

Arguments

clust.fun

Function specifying the function to use to do the clustering. The function should apply a hierarchical clustering algorithm and take a data matrix as input. If NULL, the stats::hclust function is used by default.

metric

String specifying the distance metric to use in dist.fun. If NULL, the default method of dist.fun is used.

dist.fun

Function specifying the function to use to compute the distance matrix. The function should accept a data matrix and a method= string (used to accept metric) and return a dissimilarity matrix of type dist. If NULL, the stats::dist function is used by default.

method

String specifying the agglomeration method to use in hclust.

cut.fun

Function specifying the method to use to cut the dendrogram. The first argument of this function should be the output of hclust, and the return value should be an atomic vector specifying the cluster assignment for each observation. Defaults to cutree if cut.dynamic=FALSE and cutreeDynamic otherwise.

cut.dynamic

Logical scalar indicating whether a dynamic tree cut should be performed using the dynamicTreeCut package.

cut.height, cut.number

Deprecated, use h and k in cut.params instead.

cut.params

Further arguments to pass to cut.fun.

...

Deprecated, more arguments to add to cut.params.

x

A numeric matrix-like object where rows represent observations and columns represent variables.

BLUSPARAM

A HclustParam object.

full

Logical scalar indicating whether the hierarchical clustering statistics should be returned.

Details

To modify an existing HclustParam object x, users can simply call x[[i]] or x[[i]] <- value where i is any argument used in the constructor.

If cut.fun=NULL, cut.dynamic=FALSE and cut.params does not have h or k, clusterRows will automatically set h to half the tree height when calling cutree.

Value

The HclustParam constructor will return a HclustParam object with the specified parameters.

The clusterRows method will return a factor of length equal to nrow(x) containing the cluster assignments. If full=TRUE, a list is returned with clusters (the factor, as above) and objects (a list containing dist, the distance matrix; and hclust, the output of hclust).

Author(s)

Aaron Lun

See Also

dist, hclust and cutree, which actually do all the heavy lifting.

cutreeDynamic, for an alternative tree cutting method to use in cut.fun.

Examples

clusterRows(iris[,1:4], HclustParam())
clusterRows(iris[,1:4], HclustParam(method="ward.D2"))
clusterRows(iris[,1:4], HclustParam(metric = "canberra", dist.fun = vegan::vegdist))
clusterRows(iris[,1:4], HclustParam(clust.fun=fastcluster::hclust))


LTLA/bluster documentation built on Sept. 8, 2024, 4:37 a.m.