# R. function hclust, euclidean distances and cosines

My data is a table of cosines and I want to analyze it with hclust, which works on squared Euclidean distances.

shall I do:

d <- dist(mydata, method = "euclidean") fit <- hclust(d, method="ward")

or rather:

d=(dist(mydata))^2
fit <- hclust(d, method="ward")

I don't know how to treat my cosines with hclust, which needs squared Euclidean distances.

thanks!!!

• $r$ is directly convertible to squared Euclidean $d^2=2(1-r)$. Jul 24, 2014 at 16:01
• do you mean that the cosine is directly convertible into squared euclidean distances? what is r in your comment? Jul 24, 2014 at 16:22
• Pardon, I ment $cos$. Pearson $r$ is cosine. The formula is correct. Please read details under the link. Jul 24, 2014 at 16:29
• thanks! ok. But have you ever tried hclust in R? it should work with Euclidean square distances when the ward method is called, but instead it gives error. do you have experience with R and with the hclust function there? Jul 24, 2014 at 20:28
• Sorry, I've never user the function. Please consult the documentation Jul 24, 2014 at 21:09