SparseClustering: Sparse Clustering

View source: R/SparseClustering.R

SparseClusteringR Documentation

Sparse Clustering

Description

Implements the sparse clustering methods of [Witten/Tibshirani, 2010].

Usage

SparseClustering(DataOrDistances, ClusterNo = 0, Type = "Hierarchical",

                 ColorTreshold = 0, Silent = FALSE, NoPerms = 10,

                 Wbounds, PlotIt = FALSE, ...)

Arguments

DataOrDistances

Either a [1:n,1:d] matrix containing the dataset to be clustered, with n cases and d variables, or a symmetric [1:n,1:n] distance matrix.

ClusterNo

Numeric scalar specifying the number of clusters at which to cut the tree when Type = "Hierarchical", or the number of clusters to construct when Type = "kmeans".

Type

Optional character scalar selecting "Hierarchical" or "kmeans". The default is "Hierarchical".

ColorTreshold

A finite numeric scalar used when Type = "Hierarchical". If it is nonzero and ClusterNo = 0, the value is interpreted on the dendrogram height scale. For a monotone ultrametric hierarchy, stats::rect.hclust() draws rectangles at this height, and Cls is returned from the corresponding cut. If the fusion heights are non-monotone, only a horizontal reference line is drawn and Cls = NULL.

Silent

Optional logical scalar passed to the subordinate sparcl functions' silent argument. The default is FALSE.

NoPerms

Optional numeric scalar specifying the number of permutations.

Wbounds

Optional numeric vector defining the range of tuning parameters to consider. This is the L1 bound on the feature weights w [Witten/Tibshirani, 2010].

PlotIt

If TRUE and ClusterNo > 0, plots the dendrogram using ClusterDendrogram. If TRUE and ClusterNo = 0, plots the dendrogram using base R graphics. The default is FALSE.

...

Further arguments passed to HierarchicalSparseCluster or KMeansSparseCluster, depending on Type.

Value

A list with the following components:

Cls

A numerical vector of length n defining the classification. It has k unique values representing the arbitrary cluster labels.

Object

The object returned by the selected clustering algorithm.

Dendrogram

The hierarchical clustering tree when Type = "Hierarchical".

Note

Clustering quality can differ between sparse hierarchical clustering applied to raw data and the same method applied to precomputed distances.

Author(s)

Quirin Stier, Michael Thrun

References

[Witten/Tibshirani, 2010] Witten, D. and Tibshirani, R.: A Framework for Feature Selection in Clustering. Journal of the American Statistical Association, Vol. 105(490), pp. 713-726, 2010.

Examples




# Hepta
data("Hepta")
Data <- Hepta$Data
V1 <- SparseClustering(Data, ClusterNo = 7, Type = "kmeans")
Cls1 <- V1$Cls

V2 <- SparseClustering(Data, ClusterNo = 7, Type = "Hierarchical")
Cls2 <- V2$Cls

InputDistances <- parallelDist::parDist(Data, method = "euclidean")
DistanceMatrix <- as.matrix(InputDistances)
V3 <- SparseClustering(
  DistanceMatrix,
  ClusterNo = 7,
  Type = "Hierarchical"
)
Cls3 <- V3$Cls

set.seed(1)
Data <- matrix(rnorm(100 * 50), ncol = 50)
y <- c(rep(1, 50), rep(2, 50))
Data[y == 1, 1:25] <- Data[y == 1, 1:25] + 2

V1 <- SparseClustering(Data, ClusterNo = 2, Type = "kmeans")
Cls1 <- V1$Cls


FCPS documentation built on Oct. 3, 2026, 9:06 a.m.