[R] hcluster with linkage median
Kennedy
henrik.aldberg at gmail.com
Mon Sep 27 17:22:50 CEST 2010
Hi,
I want to perform a hierarchical clustering using the median as linkage
metric. As I understand it the function hcluster in package amap have this
option but it does not produce the results that I expect.
In the example below M is a matrix of similarities that is transformed into
a matrix of dissimilarities D.
> D
[,1] [,2] [,3] [,4] [,5]
[1,] 1.0 0.9 0.2 0.2 0.1
[2,] 0.9 1.0 0.7 1.0 0.0
[3,] 0.2 0.7 1.0 0.8 0.8
[4,] 0.2 1.0 0.8 1.0 0.5
[5,] 0.1 0.0 0.8 0.5 1.0
Since [2,5]=0 the objects 2 and 5 should be grouped together in the first
step as is done by the agnes function but hcluster start by clustering
objects 3 and 4. Why is this?
Regards
Henrik
library(cluster)
library(amap)
# Create matrix M
M <- matrix(nr=5,nc=5)
M[,1] <- c(0,1,8,8,9)
M[,2] <- c(1,0,3,0,10)
M[,3] <- c(8,3,0,2,2)
M[,4] <- c(8,0,2,0,5)
M[,5] <- c(9,10,2,5,0)
# Create matrix D
n <- dim(M)[1]
o <- matrix(1,n,n)
mn <- (1/max(M))*M
D <- o-mn
# Clustering using hcluster
ce <- hcluster(D,link="median")
plot(ce)
# Clustering using agnes
av <- agnes(D,diss=T,method="average")
pltree(av)
--
View this message in context: http://r.789695.n4.nabble.com/hcluster-with-linkage-median-tp2715585p2715585.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list