Testing for gender composition between groups
For analysis of your clusters you can use the silhouette coefficient or silhouette width. These are available in cluster and factoextra package in R.

I will explain what basically in silhouette analysis:

The silhouette coefficient is calculated as follows:

1) For each observation i, it calculates the average dissimilarity between i and all the other points within the same cluster which i belongs. Let’s call this average dissimilarity “Di”.

2) Now we do the same dissimilarity calculation between i and all the other clusters and get the lowest value among them. That is, we find the dissimilarity between i and the cluster that is closest to i right after its own cluster. Let’s call that value “Ci”

3) The silhouette (Si) width is the difference between Ci and Di (Ci — Di) divided by the greatest of those two values (max(Di, Ci)).

Si = (Ci — Di) / max(Di, Ci)

So, the interpretation of the silhouette width is the following:


Si > 0 means that the observation is well clustered. The closest it is to 1, the best it is clustered.
Si &lt; 0 means that the observation was placed in the wrong cluster.
Si = 0 means that the observation is between two clusters.


Basic code to calculate the above and visualise:

library(cluster)
library(factoextra)

sil &lt;- silhouette(clustering$cluster, dist(input))
fviz_silhouette(sil)