This function runs many existing procedures for determining how many clusters are present in data. It returns the number of clusters based on the maximum consensus. In case of ties, it will select the solution with fewer clusters.

n_clusters(
  x,
  standardize = TRUE,
  force = FALSE,
  package = c("NbClust", "mclust", "cluster", "M3C"),
  fast = TRUE,
  ...
)

Arguments

x

A data frame.

standardize

Standardize the dataframe before clustering (default).

force

Logical, if TRUE, factors are converted to numerical values in order to be included in the data for determining the number of clusters. By default, factors are removed, because most methods that determine the number of clusters need numeric input only.

package

Package from which methods are to be called to determine the number of clusters. Can be "all" or a vector containing "NbClust", "mclust", "cluster" and "M3C".

fast

If FALSE, will compute 4 more indices (sets index = "allong" in NbClust). This has been deactivated by default as it is computationally heavy.

...

Arguments passed to or from other methods.

Note

There is also a plot()-method implemented in the see-package.

Examples

library(parameters)
# \donttest{
if (require("mclust", quietly = TRUE) && require("NbClust", quietly = TRUE) &&
  require("cluster", quietly = TRUE)) {
  n_clusters(iris[, 1:4], package = c("NbClust", "mclust", "cluster"))
}
#> # Method Agreement Procedure:
#> 
#> The choice of 2 clusters is supported by 12 (42.86%) methods out of 28 (CH, Cindex, DB, Silhouette, Beale, Ratkowsky, PtBiserial, McClain, Dunn, SDindex, Mixture, Tibs2001SEmax).
# }