I want to perform a Hiearchical Clustering in R but I'm facing some problems handling the results. I'm using agnes
function, which gives me a dendogram and the agglomerative coefficient and so on. Now, how can I find which are the most significant Clusters? How can I get the observations that are Clustered in the Cluster number X, for instance? I want to get the points inside each cluster.
Thank you so much!
You have used hierarchical clustering. What you get back is a hierarchy, not a clustering. If you want to see clusters, you have to decide how many clusters or equivalently, where you want to cut the tree. You can then use cutree
to group the observations into clusters. Here is a quick example. Since you do not provide any data, I will use the built-in iris data as an example.
library(cluster)
AG = agnes(iris[,1:4])
## use the hierarchy to make 3 clusters
cutree(AG, 3)
[1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
[38] 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
[75] 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 2 3 3 3 3 2 3 3 3 3
[112] 3 3 2 2 3 3 3 3 2 3 2 3 2 3 3 2 2 3 3 3 3 3 2 3 3 3 3 2 3 3 3 2 3 3 3 2 3
[149] 3 2