我做了一個可重現的例子,我在pvclust中遇到了麻煩。我的目標是在分層簇樹形圖中選擇理想的簇。我聽說過'pvclust',但不知道如何使用它。此外,如果任何人有除此之外的其他建議,以確定理想的羣集,這將是非常有益的。R - 'pvclust'中的分層聚類問題
提供我的代碼。
library(pvclust)
employee<- c('A','B','C','D','E','F','G','H','I',
'J','K','L','M','N','O','P',
'Q','R','S','T',
'U','V','W','X','Y','Z')
salary<-c(20,30,40,50,20,40,23,05,56,23,15,43,53,65,67,23,12,14,35,11,10,56,78,23,43,56)
testing90<-cbind(employee,salary)
testing90<-as.data.frame(testing90)
head(testing90)
testing90$salary<-as.numeric(testing90$salary)
row.names(testing90)<-testing90$employee
testing91<-data.frame(testing90[,-1])
head(testing91)
row.names(testing91)<-testing90$employee
d<-dist(as.matrix(testing91))
hc<-hclust(d,method = "ward.D2")
hc
plot(hc)
par(cex=0.6, mar=c(5, 8, 4, 1))
plot(hc, xlab="", ylab="", main="", sub="", axes=FALSE)
par(cex=1)
title(xlab="Publishers", main="Hierarchal Cluster of Publishers by eCPM")
axis(2)
fit<-pvclust(d, method.hclust="ward.D2", nboot=1000, method.dist="eucl")
錯誤上前指出:
Error in names(edges.cnt) <- paste("r", 1:rl, sep = "") :
'names' attribute [2] must be the same length as the vector [0]
您能指定您在MRE中使用的庫嗎? – erasmortg
剛剛添加庫(pvclust)@erasmortg – analytics
嗨@analytics,根據你得到的答案,我會提到,如果你還想要可視化結果,你可以參考以下內容:https://cran.r-project .org/web/packages/dendextend/vignettes/introduction.html#denixtend R包中的#pvclust文檔: –