Skip to contents

k-means clustering with a full model-object contract

Usage

morie_cluster(
  x,
  k = 2L,
  scale = FALSE,
  na_action = c("omit", "fail"),
  case_labels = NULL,
  nofit = FALSE,
  seed = 42L
)

Arguments

x

A numeric matrix or data.frame (numeric columns used).

k

Number of clusters.

scale

Standardise columns before clustering. Applying scale removes the dominance of large-variance columns; not applying it lets them dominate the distance metric – the examples contrast both.

na_action

"omit" (drop incomplete rows) or "fail" (error).

case_labels

Optional labels for cases when x has no row names.

nofit

If TRUE, return an unfitted specification.

seed

RNG seed.

Value

A morie_cluster object (or morie_cluster_spec if nofit = TRUE) whose cluster labels are ordered by decreasing size.

Examples

# with vs without scaling changes which columns drive the clusters
morie_cluster(iris[1:4], k = 3)
#> Warning: input has no row names; using positional labels
#> <morie_cluster> k=3  n=150
#>   sizes (largest first): 62, 50, 38 
#>   assignments (first rows):
#>  1  2  3  4  5  6  7  8  9 10 
#>  2  2  2  2  2  2  2  2  2  2 
#>   ... 140 more
morie_cluster(iris[1:4], k = 3, scale = TRUE)
#> Warning: input has no row names; using positional labels
#> <morie_cluster> k=3  n=150
#>   sizes (largest first): 53, 50, 47 
#>   assignments (first rows):
#>  1  2  3  4  5  6  7  8  9 10 
#>  2  2  2  2  2  2  2  2  2  2 
#>   ... 140 more