Min-Han Tan
2004-Dec-15 20:55 UTC
[R] hclust and heatmap - slightly different dendrograms?
Good afternoon, I ran heatmap and hclust on the same matrix x (strictly, I ran heatmap(x), and hclust(dist(t(x))), and realized that the two dendrograms were slightly different, in that the left-right arrangement of one pair of subclusters (columns) was reversed in the two functions (but all individual columns were grouped correctly). Looking through the code for heatmap as a most definite nonexpert, it seems to me that hclust is also invoked by heatmap.> heatmapfunction (x, Rowv = NULL, Colv = if (symm) "Rowv" else NULL, distfun = dist, hclustfun = hclust, add.expr, symm = FALSE, ... hcr <- hclustfun(distfun(x)) ddr <- as.dendrogram(hcr) .... hcc <- hclustfun(distfun(if (symm) x else t(x))) ddc <- as.dendrogram(hcc) I understand it is possible to add Rowv=NA and order the samples as per hclust, but I'm just wondering if there is a reason for this observation. Any pointers would be very much appreciated. Thanks! Min-Han Tan
Hierarchical clustering does NOT give an ordering for the clusters. It only gives the clustering, so order is not invariant. Sean ----- Original Message ----- From: "Min-Han Tan" <minhan.science at gmail.com> To: <r-help at stat.math.ethz.ch> Sent: Wednesday, December 15, 2004 3:55 PM Subject: [R] hclust and heatmap - slightly different dendrograms?> Good afternoon, > > I ran heatmap and hclust on the same matrix x (strictly, I ran > heatmap(x), and hclust(dist(t(x))), and realized that the two > dendrograms were slightly different, in that the left-right > arrangement of one pair of subclusters (columns) was reversed in the > two functions (but all individual columns were grouped correctly). > > Looking through the code for heatmap as a most definite nonexpert, it > seems to me that hclust is also invoked by heatmap. > >> heatmap > function (x, Rowv = NULL, Colv = if (symm) "Rowv" else NULL, > distfun = dist, hclustfun = hclust, add.expr, symm = FALSE, > ... > > hcr <- hclustfun(distfun(x)) > ddr <- as.dendrogram(hcr) > > .... > hcc <- hclustfun(distfun(if (symm) > x > else t(x))) > ddc <- as.dendrogram(hcc) > > > I understand it is possible to add Rowv=NA and order the samples as > per hclust, but I'm just wondering if there is a reason for this > observation. Any pointers would be very much appreciated. > > Thanks! > > Min-Han Tan > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html >