Learn R Programming

fdm2id (version 1.0.1)

kmeans.getk: Estimation of the number of clusters for K-means

Description

Estimate the optimal number of cluster of the K-means clustering method.

Usage

kmeans.getk(
  d,
  max = 9,
  criterion = c("pseudo-F", "silhouette", "gap", "elbow"),
  nstart = 10,
  B = 100,
  graph = FALSE,
  seed = NULL
)

Value

The number of clusters retained by the chosen criterion.

Arguments

d

The dataset (matrix or data.frame).

max

The largest number of clusters considered. Values from 2 to max are evaluated (from 1, for "gap" and "elbow", which are defined there).

criterion

How the number of clusters is chosen: "none" (the default, use k as it is), "pseudo-F", "silhouette", "gap" or "elbow". With any but the first, k is read as the largest number of clusters to consider. See the Details section.

nstart

The number of random sets chosen for kmeans initialization.

B

The number of bootstrap samples used by criterion = "gap".

graph

A logical indicating whether or not a graphic should be plotted.

seed

A specified seed for random number generation.

References

Tibshirani, R., Walther, G. and Hastie, T. (2001). Estimating the number of clusters in a data set via the gap statistic. Journal of the Royal Statistical Society: Series B, 63(2), 411-423.

See Also

pseudoF, KMEANS, kmeans, silhouette, clusGap

Examples

Run this code
require (datasets)
data (iris)
kmeans.getk (iris [, -5])
kmeans.getk (iris [, -5], criterion = "silhouette")
kmeans.getk (iris [, -5], criterion = "elbow")
# \donttest{
# The gap statistic resamples, so it is much slower than the other three.
kmeans.getk (iris [, -5], criterion = "gap", B = 20, seed = 0)
# }

Run the code above in your browser using DataLab