寻找类似于 SIMPROF 的聚类分析,但允许每个类别进行许多观察

Looking for analysis that clusters like SIMPROF, but allows for many observations per category

我需要 运行 对一些生物数据进行聚类或相似性分析,我正在寻找类似于 SIMPROF 给出的输出。又名树状图或层次聚类。

但是,我每组有 3200 observations/rows。 SIMPROF,请参见此处的示例,

library(clustsig)
usarrests<-USArrests[,c(1,2,4)]
rownames(usarrests)<-state.abb
# Run simprof on the data
res <- simprof(data= usarrests, 
               method.distance="braycurtis")
# Graph the result
pl.color <- simprof.plot(res)

似乎期望每组只观察一次(本例中为美国各州)。 现在,我的生物数据(总共 140k 行)每组大约有 3200 个 obs。 我试图将在提供的变量中具有相似表示的组聚集在一起。 就像在上面的示例中一样,AK 将由多个观察值表示。 function/package/analysis 我最好的选择是什么?

干杯, 莫


论文中的例子:

经过进一步思考,解决方案变得显而易见。

我没有使用长格式的所有观测值 (200k),而是将采样的经度和深度设为一个变量,用作样带上的采样单元。因此,最终得到 3800 列经度 - 深度组合和 61 行分类群,值变量是分类群的丰度(如果你想聚类采样单位,那么你必须转置 df)。这对于 hclust 或 SIMPROF 是可行的,因为现在二次复杂度仅适用于 61 行(与我一开始尝试的 ~200k 相反)。

干杯

这是一些代码:

library(reshape2)
library(dplyr)

d4<-d4 %>% na.omit() %>% arrange(desc(LONGITUDE_DEC))

# make 1 variable of longitude and depth that can be used for all taxa measured, like 
#community ecology sampling units
d4$sampling_units<-paste(d4$LONGITUDE_DEC,d4$BIN_MIDDEPTH_M)

d5<-d4 %>% select(PREDICTED_GROUP,CONCENTRATION_IND_M3,sampling_units)
d5<-d5%>%na.omit()

# dcast data frame so that you get the taxa as rows, sampling units as columns w
# concentration/abundance as values.
d6<-dcast(d5,PREDICTED_GROUP ~ sampling_units, value.var = "CONCENTRATION_IND_M3")

d7<-d6 %>% na.omit()
d7$PREDICTED_GROUP<-as.factor(d7$PREDICTED_GROUP)

# give the rownames the taxa names
rownames(d7)<-paste(d7$PREDICTED_GROUP)

#delete that variable that is no longer needed
d7$PREDICTED_GROUP<-NULL

library(vegan)

# calculate the dissimilarity matrix with vegdist so you can use the sorenson/bray 
#method
distBray <- vegdist(d7, method = "bray") 

# calculate the clusters with ward.D2
clust1 <- hclust(distBray, method = "ward.D2")
clust1

#plot the cluster dendrogram with dendextend
library(dendextend)
library(ggdendro)
library(ggplot2)

dend <- clust1 %>% as.dendrogram %>%
  set("branches_k_color", k = 5) %>% set("branches_lwd", 0.5)  %>%  set("clear_leaves") %>% set("labels_colors", k = 5)  %>% set("leaves_cex", 0.5) %>%
  set("labels_cex", 0.5)
ggd1 <- as.ggdend(dend)
ggplot(ggd1, horiz = TRUE)