0
$\begingroup$

I am pretty new to k-means and cluster analysis methods, but I am trying to do it on 5 different measures of inequality and redistribution (Gini, P90/P10, Atkinson with different parameters and the percentage of redistribution defined as difference between Gini pre and post social transfers) to check how the 15 countries I have are grouped based on these measures. I am referring to the 4 Welfare regimes defined in literature, so using k=4 as exogenous information and applying the k-means method for clustering.

However, using R in both kmeans command and eclust command from factorextra package the first argument is a matrix and/or a data frame. What is the difference if I use an Euclidean distance matrix as input? For example, what's the mathematical/computational difference between using the following:

hc8<-subset(wave_8, select = c(Gini.Pareto, P90.P10.Pareto, Atkinson.1, Atkinson.2, percent))
hc8 <- scale(hc8)

res.kmean8<-eclust(hc8, "kmeans", k=4, hc_method="ward.D2") 

and using, instead,

res.kmean8<-eclust(dist(hc8)^2, "kmeans", k=4, hc_method="ward.D2")

Thank you for the help and clarification

$\endgroup$
0
$\begingroup$

Kmeans cannot use a distance matrix.

In order to compte means, it needs to have vector data.

If you pass a distance matrix, it will treat the rows as vectors and compute averages of these distances, and squared errors there. This adds hard to understand bias.

The method is just very designed to squared Euclidean.

If you want to use a distance matrix, use PAM (k-medoids) instead. If you want to minimize Euclidean distances, PAM can find better solutions than k-means (but does not necessarily so, because it is constrained to use data points as centers).

$\endgroup$
  • $\begingroup$ Sorry to bother again, but so, the main differences between the two approach in terms of R coding is that k-means within the eclust function is internally computing the Euclidean distances to create the clusters, whereas the PAM works as well if you use a distance matrix as input? Thanks $\endgroup$ – Luca Giangregorio Oct 12 '19 at 16:51
  • $\begingroup$ See the documentation of the functions for the input requirements. $\endgroup$ – Has QUIT--Anony-Mousse Oct 12 '19 at 20:27

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.