I have a table of similarities expressed through cosines and am trying to do some cluster analysis in R, using hclust
and method=ward
.
First I need to turn cosines into squared Euclidean distances, knowing that $d=2(1-\cos)$. No problem. I turned myData
into myDataDist
.
But then when I use hclust (myDataDist, method=ward)
it gives me an error:
must have n >= 2 objects to cluster
The craziest thing is that if I turn the table of cosines into Euclidean distances with the dist
function: myDataDist <- dist(myData, method = "euclidean")
it works just fine, but then the dendrogram plotted by hclust
is wrong. (I know because I tried with another clustering program.)
Has anybody checked the code of dist
or ward
methods in R? Why doesn't hclust
work as it should, with Euclidean squared distances computed manually as $d=2(1-\cos)$?
d a dissimilarity structure as produced by dist
. Also how do you know the dendrogramm is wrong? $\endgroup$