This function is meant to be used with compute_metric. For Gap statistic, use cluster::maxSE().

optimal_score(x, method = c("firstmax", "globalmax", "firstmin", "globalmin"))

Arguments

x

a numeric vector

method

one of "firstmax", "globalmax", "firstmin" or "globalmin"

Value

the index (not k) of the identified maximum or minimum score

Examples

data_to_cluster <- iris[c("Petal.Length", "Sepal.Length")]
dmat <- compute_dmat(data_to_cluster, "euclidean", TRUE)
clusters <- compute_clusters(dmat, "complete")
res <- compute_metric(dmat, clusters, "dunn")
optimal_score(res$score, method = "firstmax")
#> [1] 3