clustMixType package: find Silhouette value of each cluster

Using the clustMixType package I'm trying to get the silhouette values of the following dataset using the example in page 13 here:

n   <- 10
prb <- 0.99
muk <- 2.5

x1 <- sample(c("A","B"), 2*n, replace = TRUE, prob = c(prb, 1-prb))
x1 <- c(x1, sample(c("A","B"), 2*n, replace = TRUE, prob = c(1-prb, prb)))
x1 <- as.factor(x1)

x2 <- sample(c("A","B"), 2*n, replace = TRUE, prob = c(prb, 1-prb))
x2 <- c(x2, sample(c("A","B"), 2*n, replace = TRUE, prob = c(1-prb, prb)))
x2 <- as.factor(x2)

x3 <- c(rnorm(n, mean = -muk), rnorm(n, mean = muk), rnorm(n, mean = -muk), rnorm(n, mean = muk))
x4 <- c(rnorm(n, mean = -muk), rnorm(n, mean = muk), rnorm(n, mean = -muk), rnorm(n, mean = muk))

x <- data.frame(x1,x2,x3,x4)

The following code plots the mean silhouette value for several k number of clusters:

library(clustMixType)
Essil <- numeric(5)
for(i in 2:6){
  kpres <- kproto(x, k = i,na.rm=FALSE )
  val_sil<-validation_kproto(method = "silhouette", object=kpres)
  Essil[i] <- val_sil
}
plot(1:6, Essil, type = "b", ylab = "Silhouette", xlab = "Number of clusters")
Essil

But now I'm trying to find the silhouette of each cluster, instead of the mean silhouette, is that possible?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.