So, I'm relatively new to using Gower's distance to do cluster analysis. I've done some research on this for a little while and like the fact it can incorporate categorical variables. To get a better understanding of how it works in practice, I tried simulating data and playing around with the PAM function in R. I simulated my data as such:
let <- LETTERS[1:5] dich <- c(1L,0L) a <- as.data.frame(cbind(rnorm(50, 100, 25), sample(let, 50, replace=T), sample(dich, 50, replace=T))) colnames(a) <- c("iq","let","dich") rownames(a) <- 1:50
I then ran it through PAM with various values for number of clusters (k). When I generate the silhouette plots to check how well the observations fit the assigned cluster, it always seems to be at it's best at k=10, with an average silhouette width of .49 (one observation was put into its own cluster).
Obviously this is no coincidence (5 letters times 2 values of dichotomous variable = 10). My assumption is that the algorithm makes the cuts at the categorical level before evaluating the continuous. Is this correct? Or is it the way I'm generating the data that is creating this? I also made sure there wasn't balanced amounts of observations across the categorical variables.
If my assumption is accurate, I don't know if I want cluster assignments made that way. I'll be using demographic data, and I don't want one cluster to be completely males and one cluster completely females. Any insight would be most helpful!
Here's my clustering code:
dist <- daisy(a, metric="gower") clust <- pam(dist, k=10, diss=T) plot(clust)