apaClustering.kMeans.FromDistances(Distances, nClusters, nMultiStarts)
=apaClustering.kMeans.FromDistances(Distances, nClusters, nMultiStarts)Result
Statistical classification with the k-means algorithm, starting from a distance matrix instead of a data matrix. Returns an n x 1 vector with the cluster label of each object, numbered from 0 to nClusters - 1.
Syntax
Distances: n x n symmetric distance matrix with zero diagonal and non-negative entries, e.g. from apaDistances.Euclidian
nClusters: number of clusters, integer between 1 and n
nMultiStarts: optional; number of k-means++ starts, integer, at least 1; the solution with the lowest within-cluster sum of squares is used; default: 10
Algorithm
k-means only needs squared distances between objects and cluster centroids, so the algorithm is carried out on the distance matrix alone: the squared distance of object i to the centroid of cluster C is the mean of d(i,j)² over j in C minus half the mean of d(j,l)² over all pairs j, l in C, and the within-cluster sum of squares of C is the sum of d(j,l)² over all pairs j < l in C divided by the size of C. The k-means++ initialization draws new starting objects with probability proportional to the squared distance to the nearest object already chosen.
Remarks
If Distances contains the Euclidean distances between the rows of a data matrix, the function returns the same partition as apaClustering.kMeans applied to that data matrix; when several starts reach the same optimum, the numbering of the clusters can differ. Other distance measures can be used as well; the result is then the k-means classification of the objects embedded with these distances. The random starts use a fixed seed, so results are reproducible.
