## Hierarchical clustering (9/05/24) ?agnes ?eurodist data(eurodist) as.matrix(eurodist)[1:5, 1:5] library(cluster) #single linkage agnes.single<-agnes(eurodist, method="single") # agglomerative coefficient agnes.single$ac pltree(agnes.single, cex=0.8, hang = -1, main = "agnes (single)", xlab="", sub ="") # Oppure ?hclust hc<-hclust(eurodist, method="single") plot(hc, hang=-1) #complete linkage agnes.comp<-agnes(eurodist, method="complete") agnes.comp$ac pltree(agnes.comp, cex = 0.8, hang = -1, main = "agnes (complete)", xlab="", sub ="") #average linkage agnes.ave<-agnes(eurodist, method="average") agnes.ave$ac pltree(agnes.ave, hang=-1, cex = 0.7, main="") abline(h=1000) rect.hclust(agnes.ave, k = 4, border = 3:7) hc<-cutree(agnes.ave, 4) cnames<-row.names(as.matrix(eurodist)) cnames[hc==1] cnames[hc==2] cnames[hc==3] cnames[hc==4] # Ward's method agnes.Ward<-agnes(eurodist, method="ward") agnes.Ward$ac pltree(agnes.Ward, cex = 0.8, hang = -1, main = "agnes (Ward)", xlab="", sub ="")