[R] Cutting hierarchical cluster tree at specific height fails
David L Carlson
dcarlson at tamu.edu
Wed Jul 9 17:31:23 CEST 2014
To cut the tree, the clustering algorithm must produce consistently increasing height values with no reversals. You used one of the two options in hclust that does not do this. Note the following from the hclust manual page:
"Note however, that methods "median" and "centroid" are not leading to a monotone distance measure, or equivalently the resulting dendrograms can have so called inversions (which are hard to interpret)."
The cutree manual page:
"Cutting trees at a given height is only possible for ultrametric trees (with monotone clustering heights)."
Use a different method (but not median).
-------------------------------------
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77840-4352
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Johannes Radinger
Sent: Wednesday, July 9, 2014 7:07 AM
To: R help
Subject: [R] Cutting hierarchical cluster tree at specific height fails
Hi,
I'd like to cut a hierachical cluster tree calculated with hclust at a
specific height.
However ever get following error message:
"Error in cutree(hc, h = 60) :
the 'height' component of 'tree' is not sorted (increasingly)"
Here is a working example to show that when specifing a height in cutree()
the code fails. In contrast, specifying the number of clusters in cutree()
works.
What is the exact problem and how can I solve it?
x <- c(rnorm(100,50,10),rnorm(100,200,25),rnorm(100,80,15))
y <- c(rnorm(100,50,10),rnorm(100,200,25),rnorm(100,150,25))
df <- data.frame(x,y)
plot(df)
hc <- hclust(dist(df,method = "euclidean"), method="centroid")
plot(hc)
df$memb <- cutree(hc, h = 60) # this does not work
df$memb <- cutree(hc, k = 3) # this works!
plot(df$x,df$y,col=df$memb)
Thank you for your hints!
Best regards,
Johannes
[[alternative HTML version deleted]]
______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list