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)

migrated from stackoverflow.com Jan 16 '15 at 7:46

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

  • 1
    $\begingroup$ Why are you not looking at the code? $\endgroup$ – DWin Jan 15 '15 at 23:38
  • $\begingroup$ 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? $\endgroup$ – ttnphns Jan 16 '15 at 9:03
  • $\begingroup$ @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. $\endgroup$ – wesly82 Jan 16 '15 at 16:01
  • $\begingroup$ 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. $\endgroup$ – DWin Jan 16 '15 at 16:31

I think that there was a misteke in the simulating data set. the cbind generates a matrix, so there was no numeric variables. If there was : a<-data.frame(cbind(rnorm(50, 100, 25), ... the numeric variable (the first column) was not convert to nominal


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.