Cluster quality across a range of k
cluster_sweep(
data,
x,
ks,
frame = NULL,
key = NULL,
value = NULL,
distance = "euclidean",
scale_units = FALSE,
FUN = cluster_scale,
...
)Long data: unit codes, one or more identifier columns saying which observation each row is, and a value column. A unit that is not observed over the same set as the others is an error rather than a hole.
A NestedScale.
Values of k to try.
Frame whose units are clustered. Defaults to the atom frame.
Columns of data; inferred when unambiguous.
A name from list_scale_distances().
Standardise each unit's profile before measuring;
see scale_distance().
The clustering function to sweep: cluster_scale() (default)
or cluster_contiguous().
Passed to FUN.
A data frame with one row per k: k, within (total
within-cluster sum of distances to the cluster medoid), silhouette
(average, NA at k = 1), and smallest (the size of the smallest
cluster, which is often what rules a k out).
s <- scale_example()
d <- data.frame(
unit = rep(scale_units(s), each = 4),
t = rep(sprintf("t%d", 1:4), 7), v = as.numeric(seq_len(28))
)
cluster_sweep(d, s, ks = 2:4)
#> k within silhouette smallest
#> 1 2 48 0.5147392 3
#> 2 3 32 0.4197279 2
#> 3 4 24 0.2387755 1