Cross Validated is a question and answer site for people interested in statistics, machine learning, data analysis, data mining, and data visualization. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Good Morning,

By comparing the dendrograms produced by the clustergram object and the "manual" approach i.e. pdist -> linkage -> dendrogram I found they are different, but cannot find an explanation for that difference.

Clustergram documentation says that the default distance used is 'Euclidean' and the default linkage method is 'Average', same parameters I used for pdist and linkage functions.

I thought it might be related with the standardization performed by clustergram, so I used zscore for standardizing first my matrix and then each column separately, but the dendrograms are still different as compared with the one produced by clustergram.

Can somebody explain the reason behind that difference, and how can I use the "manual" approach for getting the same dendrogram?

Many thanks in advance.

Edit: I compared the results obtained by the "manual" approach with the SPSS results and they are the same.
Also I tested all different 'data processing' options with clustergram but the dendrogram keeps being different.

share|improve this question

pdist -> linkage -> dendrogram is also used in clustergram, just open the clustergram code:

dist = pdist(data, pdistArgs{:});
Z = linkage(dist, linkageArgs);


[lineH, T, Perm] = dendrogram(Z,0,dendroArgs{:},'Orientation', dendroLoc);

So the only difference can be in data preprocessing or parameters for pdist/linkage/dendrogram. I suggest you go over the clustergram parameters one by one. You can also look through the code although it is pretty long.

share|improve this answer
Yeap I print it out 40 pages!!! I'm studying it but honestly is my first time working with a Class in Matlab, so it's kind of messy for me to follow it. I found couple of things more that can make a difference like OptimalLeafOrder, Log2 Transform Data, and the Computation of the dendogram along both directions. However the only way I can imagine for evaluating this Class is by building it up step by step... and that seems to be a huge work... So any ideas are very much welcome. – Diego Oct 11 '12 at 15:39
@Diego Make sure you are clustering only by rows/columns, not by both (default is by both). – Bitwise Oct 11 '12 at 15:53
Yes, I've thought about that and performed some tests: c = clustergram(A,'Cluster','column'); and c = clustergram(A,'Cluster','all');. However both lines return the same "column" dendrogram and same heat map with different order in the heat map. – Diego Oct 11 '12 at 16:21

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.