[R] Clustering question \ dist(datmat)
Gabor Grothendieck
ggrothendieck at gmail.com
Mon Mar 27 06:09:08 CEST 2006
A distance matrix must be of class "dist". Try
hclust(as.dist(df))
On 3/26/06, kumar zaman <statbataineh at yahoo.com> wrote:
> Hello everybody. I am trying to cluster circular data (data points which are angles), thus i can not use the "dist" function in "mclust" to generate my distance matrix, I am using the function " Dij = 0.5*( 1 - cos(theta_i - theta_j)). The thing is "hclust" will not accept this distance matrix, i tried to put it in a data frame, but again i get an error message saying " Error in if (n < 2) stop("must have n >= 2 objects to cluster") : argument is of length zero". The distance matrix "dist" producing is a lower triangular one, mine is a square matrix, which i think does not matter. My question how to make "hclust" process my distance matrix, what i am doing wrong. I am sure the problem is with the distance matrix format, Any suggestions are highly apprciated, the code below shows what i have done.
>
> clust1<- as.vector(rvm(5,5,15))
> clust2<- as.vector(rvm(5,10,15))
> clust3<- as.vector(rvm(5,15,15))
> clust4<- as.vector(rvm(5,20,15))
> clust5<- as.vector(rvm(5,25,15))
> data1<- rbind(clust1,clust2,clust3,clust4,clust5)
> datmat<- matrix(data1,nrow=25,ncol=1,byrow=TRUE)
> circ.plot(datmat)
> df<- array(dim=c(25,25))
> for (i in 1:25){
> for (j in 1:25){
> df[i,j]<- 0.5*(1 - cos(datmat[i] - datmat[j]))
> }
> }
> hcA<-hclust(df,method="average")
> ****************************************************
> Ahmed
> Florida
>
>
> ---------------------------------
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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
>
More information about the R-help
mailing list