Gower's Distance issue

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)


migrated from stackoverflow.comJan 16 '15 at 7:46

This question came from our site for professional and enthusiast programmers.

• Why are you not looking at the code? – DWin Jan 15 '15 at 23:38
• I see that your data has 3 variables: a metric one, a nominal one and a binary one. The program which computes Gower coefficient for you should be informed about which is which. Did you do it correctly, in accordance with the documentation? – ttnphns Jan 16 '15 at 9:03
• @DWin Not sure what you're implying. The different variable types was intentional, since Gower can handle various data types. The question is more of trying to understand if Gower is making splits to the the dichotomous and/or categorical variables first, then uses the continuous. I don't necessarily want it to make the breaks of Male and Female first, then use the continuous variables, creating gender exclusive groups. – wesly82 Jan 16 '15 at 16:01
• After reviewing the docs for cluster::pam and cluster::daisy, my impression from the description of the algorithm on ?daisy is that there is no sequential processing as you are inferring. – DWin Jan 16 '15 at 16:31