Description Usage Arguments Value See Also Examples
Perform optimal clustering via PAM (package cluster
) and maximum Silhouette index.
1 | optimcluster(x, D=dist(x), plot=FALSE)
|
x |
Input data, either a matrix, data frame or vector. |
D |
Distance among entities in x. |
plot |
Whether to plot clustering metrics. |
optim.pam |
Optimal pam object. |
optim.nclust |
Optimal cluster number. |
silhouette.index |
Silhouette index |
Calinski.Harabasz.index |
Calinski-Harabasz(CI) index |
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()
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.