Choose the number of clusters K that maximises the silhouette, starting from a set of kernel matrices each corresponding to a different choice of K and the corresponding clusterings of the data for each of those values of K.

maximiseSilhouette(
  kernelMatrix,
  clLabels,
  maxK,
  savePNG = FALSE,
  fileName = "silhouette",
  isDistance = FALSE,
  widestGap = FALSE,
  dunns = FALSE,
  dunn2s = FALSE
)

Arguments

kernelMatrix

N X N X (maxK-1) array of kernel matrices.

clLabels

(maxK-1) X N matrix containing the clusterings obtained for different values of K.

maxK

Maximum number of clusters considered.

savePNG

If TRUE, a plot of the silhouette is saved in the working folder. Defaults to FALSE.

fileName

If savePNG is TRUE, this is the name of the png file.

isDistance

Boolean. If TRUE, the kernel matrices are interpreted as matrices of distances, otherwise as matrices of similarities.

widestGap

Boolean. If TRUE, also computes widest gap index (and plots it if savePNG is TRUE).

dunns

Boolean. If TRUE, also computes Dunn's index: minimum separation / maximum diameter (and plots it if savePNG is TRUE).

dunn2s

Boolean. If TRUE, also computes an alternative version of Dunn's index: minimum average dissimilarity between two cluster / maximum average within cluster dissimilarity (and plots it if savePNG is TRUE).

Value

The function returns a list containing:

silh

a vector of length maxK-1 such that silh[i] is the silhouette for K = i+1

K

the lowest number of clusters for which the silhouette is maximised.