Performs k-means clustering on interval data, allowing for partitioning of data points into distinct clusters.

ikmeans(
  x,
  centers,
  nstart = 10,
  distance = "euclid",
  trace = FALSE,
  iter.max = 20
)

Arguments

x

A 3D interval array representing the data to be clustered.

centers

Either the number of clusters to create or a set of pre-initialized cluster centers. If a number is provided, it specifies how many clusters to create.

nstart

The number of times to run the k-means algorithm with different starting values in order to find the best solution (default is 10).

distance

A string specifying the distance metric to use: 'euclid' for Euclidean distance or 'hausdorff' for Hausdorff distance (default is 'euclid').

trace

Logical value indicating whether to show progress of the algorithm (default is `FALSE`).

iter.max

Maximum number of iterations allowed for the k-means algorithm (default is 20).

Value

A list of clustering results, including: - `cluster`: A vector indicating the cluster assignment of each data point. - `centers`: The final cluster centers. - `totss`: Total sum of squares. - `withinss`: Within-cluster sum of squares by cluster. - `tot.withinss`: Total within-cluster sum of squares. - `betweenss`: Between-cluster sum of squares. - `size`: The number of points in each cluster. - `iter`: Number of iterations the algorithm executed.

Examples

ikmeans(iaggregate(iris, col = 5), 2)
#> Ikmeans clustering with 2 clusters of sizes: 2, 1 
#> 
#> Cluster centers:
#> , , Sepal.Length
#> 
#>   min  max
#> 1 4.9 7.45
#> 2 4.3 5.80
#> 
#> , , Sepal.Width
#> 
#>   min max
#> 1 2.1 3.6
#> 2 2.3 4.4
#> 
#> , , Petal.Length
#> 
#>    min max
#> 1 3.75 6.0
#> 2 1.00 1.9
#> 
#> , , Petal.Width
#> 
#>   min  max
#> 1 1.2 2.15
#> 2 0.1 0.60
#> 
#> Available components:
#> [1] "inter" "class"
#> 
#> Clustering vector:
#> [1] 2 1 1
#> 
#> Within-cluster sum of squares by cluster:
#> [1] 3.575 0.000
#>  (Between_SS / Total_SS =  96.2%)
#> Available components:
#> [1] "cluster"      "centers"      "totss"        "withinss"     "tot.withinss"
#> [6] "betweenss"    "size"         "iter"        
ikmeans(iaggregate(iris, col = 5), iaggregate(iris, col = 5))
#> Ikmeans clustering with 3 clusters of sizes: 1, 1, 1 
#> 
#> Cluster centers:
#> , , Sepal.Length
#> 
#>   min max
#> 1 4.3 5.8
#> 2 4.9 7.0
#> 3 4.9 7.9
#> 
#> , , Sepal.Width
#> 
#>   min max
#> 1 2.3 4.4
#> 2 2.0 3.4
#> 3 2.2 3.8
#> 
#> , , Petal.Length
#> 
#>   min max
#> 1 1.0 1.9
#> 2 3.0 5.1
#> 3 4.5 6.9
#> 
#> , , Petal.Width
#> 
#>   min max
#> 1 0.1 0.6
#> 2 1.0 1.8
#> 3 1.4 2.5
#> 
#> Available components:
#> [1] "inter" "class"
#> 
#> Clustering vector:
#> [1] 1 2 3
#> 
#> Within-cluster sum of squares by cluster:
#> [1] 0 0 0
#>  (Between_SS / Total_SS = 100.0%)
#> Available components:
#> [1] "cluster"      "centers"      "totss"        "withinss"     "tot.withinss"
#> [6] "betweenss"    "size"         "iter"