optimcluster: Optimal clustering via PAM

Description Usage Arguments Value See Also Examples

View source: R/optimcluster.R

Description

Perform optimal clustering via PAM (package cluster) and maximum Silhouette index.

Usage

1

Arguments

x

Input data, either a matrix, data frame or vector.

D

Distance among entities in x.

plot

Whether to plot clustering metrics.

Value

optim.pam

Optimal pam object.

optim.nclust

Optimal cluster number.

silhouette.index

Silhouette index

Calinski.Harabasz.index

Calinski-Harabasz(CI) index

See Also

pam

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
library(cluster)
library(plotrix)
library(MASS)

x=iris[,1:4]
D=dist(x)
#pdf('clustering_metrics.pdf', height=5, width=6)
r=optimcluster(x, plot=TRUE)
#dev.off()

# Classical multidimensional scaling (CMDS) of a data matrix, or you can choose
#+to use non-metric multidimensional scaling (NMDS) provided in MASS package
mds=cmdscale(D, 2, eig=TRUE)                  # CMDS
#mds=isoMDS(D, k=2, maxit=5000, tol=1e-6)     # NMDS

# visualize MDS output
#pdf('clustering_mds_figure.pdf', height=5, width=6)
s.class2(mds$points, as.factor(r$optim.pam$clustering), grid=FALSE, clabel=0.5, cpoint=0.9, ellipse.lwd=1)
#dev.off()

lixiangchun/lxctk documentation built on May 21, 2019, 6:44 a.m.