sil: Silhouette index and plot

View source: R/sil.R

silR Documentation

Silhouette index and plot

Description

This function creates silhouette indices and silhouette plots of each cluster. The plot presents also the mean of the silhouette indices per cluster.

Usage

sil(distdata, idmedoid, idcluster, title = "")

Arguments

distdata

A distance matrix (n x n) or dist object.

idmedoid

A vector of id medoids (see Details).

idcluster

A vector of cluster membership (see Details).

title

A title of the plot.

Details

The silhouette index of object i is calculated by

si(i)=\frac{b_i-a_i}{max(a_i, b_i)}

where a_i is the average distance of object i to all objects within the cluster, and b_i is the average distance of object i to all objects within the nearest cluster.

The idmedoid argument corresponds to the idcluster argument. If the length of idmedoid is 3, for example, the idcluster has to have 3 unique memberships, or it returns Error otherwise. The length of the idcluster has also to be equal to n (the number of objects).

Value

Function returns a list with following components:

result is a data frame of the silhouette indices for all objects

plot is the silhouette plots of each cluster.

Author(s)

Weksi Budiaji
Contact: budiaji@untirta.ac.id

References

P. J. Rousseeuw. 1987 Silhouettes: a graphical aid to the interpretation and validation of cluster analysis. Journal of Computational and Applied Mathematics, vol. 20, pp. 53-65

Examples

distiris <- as.matrix(dist(iris[,1:4]))
res <- fastkmed(distiris, 3)
silhouette <- sil(distiris, res$medoid, res$cluster)
silhouette$result[c(1:3,70:75,101:103),]
silhouette$plot


kmed documentation built on Aug. 29, 2022, 9:06 a.m.