[R] cutree with agnes
Christian Hennig
fm3a004 at math.uni-hamburg.de
Thu Dec 11 15:13:52 CET 2003
Hi,
this is rather a (presumed) bug report than a question because I can solve
my personal statistical problem by working with hclust instead of agnes.
I have done a complete linkage clustering on a dist object dm with 30
objects with agnes (R 1.8.0 on
RedHat) and I want to obtain the partition that results from a cut at
height=0.4.
I run
> cl1a <- agnes(dm, method="complete")
> cutree(cl1a,h=0.4)
[1] 1 2 3 4 5 6 3 7 3 8 9 10 3 11 12 13 14 15 3 16 17 3 18
19 20
[26] 21 3 22 18 23
But that's not true; correct is the solution obtained from hclust
> clx <- hclust(dm)
> cutree(cl1,h=0.4)
[1] 1 2 1 2 3 4 1 2 1 3 4 5 1 4 6 7 8 4 1 5 2 1 9
2 2
[26] 10 1 9 9 11
as can be seen from the dendrogram plots of hclust *and* agnes.
(Note that the dendrograms of hclust and agnes are not identical due to
the handling of ties in the distances, but the difference between the
agnes and hclust dendrogram at h=0.4 concerns only two points.)
Specifying k instead of h in cutree for agnes seems to work properly, but
that's not what I need in the general case.
I tried to reproduce this with a toy example, but it worked (too) well:
> d
[,1] [,2] [,3]
[1,] 0 1 2
[2,] 1 0 3
[3,] 2 3 0
> ad <- agnes(as.dist(d),method="complete")
> cutree(ad,h=1.5)
[1] 1 1 2
> ah <- hclust(as.dist(d))
> cutree(ah,h=1.5)
[1] 1 1 2
I can send anyone who would like to reproduce the problem (Martin?) the
original distance matrix dm (dm is a dist object) as ASCII or R-object.
Best,
Christian
***********************************************************************
Christian Hennig
Fachbereich Mathematik-SPST/ZMS, Universitaet Hamburg
hennig at math.uni-hamburg.de, http://www.math.uni-hamburg.de/home/hennig/
#######################################################################
ich empfehle www.boag-online.de
More information about the R-help
mailing list