clustboot: Bootstrap replications for clustering alorithm

View source: R/clustboot.R

clustbootR Documentation

Bootstrap replications for clustering alorithm

Description

This function does bootstrap replications for a clustering algorithm. Any hard clustering algorithm is valid.

Usage

clustboot(distdata, nclust = 2, algorithm = fastclust, nboot = 25, diss = TRUE)

Arguments

distdata

A distance matrix (n x n)/ dist object or a data frame.

nclust

A number of clusters.

algorithm

A clustering algorithm function (see Details).

nboot

A number of bootstrap replicates.

diss

A logical if distdata is a distance matrix/ object or a data frame.

Details

This is a function to obtain bootstrap evaluation for cluster results. The algorithm argument is a function where this function has two input arguments. The two input arguments are a distance matrix/ object or a data frame, and number of clusters. Then the output is only a vector of cluster memberships.

The default algorithm is fastclust applying the fastkmed function. The code of the fastclust is

fastclust <- function(x, nclust) {

res <- fastkmed(x, nclust, iterate = 50)

return(res$cluster)

}

For other examples, see Examples. It applies ward and kmeans algorithms. When kmeans is applied, for example, diss is set to be FALSE because the input of the kmclust and clustboot is a data frame instead of a distance.

Value

Function returns a matrix of bootstrap replicates with a dimension of n x b, where n is the number of objects and b is the number of bootstrap replicates.

Author(s)

Weksi Budiaji
Contact: budiaji@untirta.ac.id

References

Dolnicar, S. and Leisch, F. 2010. Evaluation of structure and reproducibility of cluster solutions using the bootstrap. Marketing Letters 21 pp. 83-101.

Examples

num <- as.matrix(iris[,1:4])
mrwdist <- distNumeric(num, num, method = "mrw")
ward.D2 <- function(x, nclust) {
res <- hclust(as.dist(x), method = "ward.D2")
member <- cutree(res, nclust)
return(member)
}
kmclust <- function(x, nclust) {
res <- kmeans(x, nclust)
return(res$cluster)
}
irisfast <- clustboot(mrwdist, nclust=3, nboot=7)
head(irisfast)
irisward <- clustboot(mrwdist, nclust=3, algorithm = ward.D2, nboot=7)
head(irisward)
iriskmeans <- clustboot(num, nclust=3, algorithm = kmclust, nboot=7, diss = FALSE)
head(iriskmeans)


kmed documentation built on Aug. 29, 2022, 9:06 a.m.