How to hierarchically cluster a data matrix in R?

点点圈 提交于 2019-12-06 12:02:52

问题


I am trying to cluster a data matrix produced from scientific data. I know how I want the clustering done, but am not sure how to accomplish this feat in R.

Here is what the data looks like:

            A1     A2     A3     B1     B2     B3     C1     C2     C3
sample1      1      9     10      2      1     29      2      5     44
sample2      8      1     82      2      8      2      8      2     28
sample3      9      9     19      2      8      1      7      2     27

Please consider A1,A2,A3 to be three replicates of a single treatment, and likewise with B and C. Sample1 are different tested variables. So, I want to hierarchically cluster this matrix in order to see the over all differences between the columns, specifically I will be making a dendrogram (tree) to observe the relatedness of the columns.

Does anyone know how to appropriately cluster something like this? I tried doing this with this:

raw.data <- read.delim("test.txt",header=FALSE,stringsAsFactors=FALSE)
dist.mat<-vegdist(raw.data,method="jaccard")
clust.res<-hclust(dist.mat)
plot(clust.res)

...However, this resulted in a tree with branches for each sample variable, instead of each column. Thanks for any suggestions!


回答1:


Just transpose your data set:

raw.data <- t(raw.data)
require(vegan)
dist.mat<-vegdist(raw.data,method="jaccard")
clust.res<-hclust(dist.mat)
plot(clust.res)


来源:https://stackoverflow.com/questions/18134064/how-to-hierarchically-cluster-a-data-matrix-in-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!