'How to get clustering on variables using gower in R?

I have a dataset with mixed types: continuous, binary, categorical.

I read some articles that using 'gower' is a good clustering distance for mixed type data. So I would like to try it out and make an exploratory heatmap (clustering both row and column). For a minimal exmaple:

library(cluster)
data(agriculture)
agriculture$test <- as.factor(ifelse(agriculture$y %% 2 == 0, "yes", "no"))
head(agriculture)
      x    y test
B  16.8  2.7   no
DK 21.3  5.7   no
D  18.7  3.5   no
GR  5.9 22.2   no
E  11.4 10.9   no
F  17.8  6.0  yes

I can get a dissimilarity matrix on sample using gower_sample_dist <- daisy(agriculture, metric = "gower"). However, if I need to get the heatmap, I would also need the clustering on variables, which I am not able to run successfully using gower_variable_dist <- daisy(t(agriculture), metric = "gower").

> daisy(t(agriculture), metric = "gower")
Error in daisy(t(agriculture), metric = "gower") : 
  x is not a dataframe or a numeric matrix.

Is there way to get a clustering/dissimlarity matrix on variables using gower?

Thank you!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source