Comparing different variables, I got a matrix with lots of missing values.

How do I have to transform the matrix below for hierarchical clustering?

enter image description here

What I have already tried:

x = read.csv("xyz.csv", sep = ";", row.names = 1, header = TRUE)
x[is.na(x)] = FALSE

# transform to correlation matrix
x = cor(t(x), method = "pearson")

# elbow method
fviz_nbclust(x, FUN = hcut, method = "wss")

# cluster with ward method
hc = hclust(dist(x), method = "ward.D2")

# show clusters
rect.hclust(hc,k=3, border="red")

This clustering result looks wrong:

enter image description here

dissimilarity matrix

Right keyword for further search "dissimilarity matrix". Now i tried to transform the matrix into a distance matrix.

x= as.dist(x, diag = TRUE)
hc = hclust(dist(x), method = "ward.D2")

that´s not a solution yet

  • $\begingroup$ That isn't a solution. It's just hiding the error. The meaning of the result is likely completely messed up. Hacking random functions together without understanding what they do never was a good idea... $\endgroup$ – Has QUIT--Anony-Mousse Jul 1 '19 at 5:58
  • $\begingroup$ thanks for that hint. i will dive deeper into that cluster method. $\endgroup$ – bartman99 Jul 2 '19 at 10:16

Your Answer

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

Browse other questions tagged or ask your own question.