View source: R/clusterquality.R
wcSilhouetteObs | R Documentation |
Compute the silhouette of each object using weighted data.
wcSilhouetteObs(diss, clustering, weights = NULL, measure="ASW")
diss |
A dissimilarity matrix or a dist object (see |
clustering |
Factor. A vector of clustering membership. |
weights |
optional numerical vector containing weights. |
measure |
"ASW" or "ASWw", the measure of the silhouette. See the WeigthedCluster vignettes. |
See the silhouette
function in the cluster
package for a detailed explanation of the silhouette.
A numeric vector containing the silhouette of each observation.
Maechler, M., P. Rousseeuw, A. Struyf, M. Hubert and K. Hornik (2011). cluster: Cluster Analysis Basics and Extensions. R package version 1.14.1 — For new features, see the 'Changelog' file (in the package source).
See also silhouette
.
data(mvad)
## Aggregating state sequence
aggMvad <- wcAggregateCases(mvad[, 17:86], weights=mvad$weight)
## Creating state sequence object
mvad.seq <- seqdef(mvad[aggMvad$aggIndex, 17:86], weights=aggMvad$aggWeights)
## Computing Hamming distance between sequence
diss <- seqdist(mvad.seq, method="HAM")
## KMedoids using PAMonce method (clustering only)
clust5 <- wcKMedoids(diss, k=5, weights=aggMvad$aggWeights, cluster.only=TRUE)
## Compute the silhouette of each observation
sil <- wcSilhouetteObs(diss, clust5, weights=aggMvad$aggWeights, measure="ASWw")
## If you want to compute the average silhouette width,
## you should take weights into account
weighted.mean(sil, w=aggMvad$aggWeights)
## Plotting sequences ordred by silhouette width,
## best classified are draw on the top.
seqIplot(mvad.seq, group=clust5, sortv=sil)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.