Hi Dave,

That's because hclust() computes 'height' as the distance between the two sets 
that are agglomerated. Consider a case with n=2:

> (d <- dist(rnorm(2)))
         1
2 2.562737
> h <- hclust(d)
> h$height
[1] 2.562737

So if we make a "phylo" object from h, it will have two edges whose lengths 
must sum to 2.56:

> t <- as.phylo(h)
> t$edge.length
[1] 1.281369 1.281369

Of course the cophenetic distances must be the same:

> cophenetic(t)
         1        2
1 0.000000 2.562737
2 2.562737 0.000000
> cophenetic(h)
         1
2 2.562737


Cheers,

Emmanuel
------Original Message------
From: David Bapst
Sender: dwba...@gmail.com
To: R Sig Phylo Listserv
Cc: Emmanuel Paradis
Subject: as.phylo.hclust
Sent: 21 Jun 2012 05:08

Hello all,

I was having some problems with getting the information I wanted from
an hclust object so decided I would make it a tree and use all the
tools I already know so well. Unfortunately, the distance structure in
the hclust structure does not seem to be preserved by as.phylo.hclust.
Instead, the tree's total depth/height seems to be halved during
conversion. See the example below.

set.seed(444)
x<-dist(rnorm(10))
hc<-hclust(x)
tr<-as.phylo.hclust(hc)

#see graphically
layout(1:2)
plot(hc)
plot(tr);axisPhylo()

#test depths
max(hc$height)==max(dist.nodes(tr)[Ntip(tr)+1,])         #FALSE

It looks like what's happening is that the edges are half as long as
they should be.

tr1<-tr
tr1$edge.length<-tr1$edge.length*2
max(hc$height)==(max(dist.nodes(tr1)[Ntip(tr1)+1,]))    #TRUE

I am running ape 3.0.4 with R 2.15.0. I notice in the change-log for
ape that there used to be an error (around version 2.5) where the
edges of as.phylo.hclust output were multiplied by 2. Maybe the
reverse bug has crept in?
-Dave


-- 
David Bapst
Dept of Geophysical Sciences
University of Chicago
5734 S. Ellis
Chicago, IL 60637
http://home.uchicago.edu/~dwbapst/
http://cran.r-project.org/web/packages/paleotree/index.html


_______________________________________________
R-sig-phylo mailing list
R-sig-phylo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo

Reply via email to