简体   繁体   English

在 R 中使用 clValid 在 cutree.default(clusterObj, nc) 中获取错误:函数 cutree 仅适用于 hclust/dendrogram/phylo 对象

[英]Using clValid in R getting Error in cutree.default(clusterObj, nc) : Function cutree is only available for hclust/dendrogram/phylo objects only

Using the default data set from Brock et al., 2008使用 Brock 等人的默认数据集,2008

install.packages("clValid", dependencies = TRUE)
library(clValid)
data("mouse")
express <- mouse[, c("M1", "M2", "M3", "NC1", "NC2", "NC3")]
rownames(express) <- mouse$ID
intern <- clValid(express, 2:6, clMethods = c("hierarchical", "kmeans", "diana", "fanny", 
"som", "pam", "sota", "clara", "model"), validation = "internal")

and getting the following:并获得以下信息:

Error in cutree.default(clusterObj, nc) : cutree.default(clusterObj, nc) 中的错误:
Function cutree is only available for hclust/dendrogram/phylo objects only.函数 cuttree 仅适用于 hclust/dendrogram/phylo 对象。

The problem seems to come from the fact that stats::cutree is masked by dendextend::cutree once the package dendextend is loaded and that dendextend::cutree does not work for objects generated with some functions of the cluster package like diana and agnes (while stats::cutree works fine).问题似乎来自这样一个事实,即stats::cutree在加载包dendextend后被dendextend::cutree屏蔽,并且dendextend::cutree不适用于使用cluster包的某些函数生成的对象,如dianaagnes (而stats::cutree工作正常)。

EDIT : this problem was observed with dendextend 1.9.0 but has been very quickly fixed by the package author after bug report .编辑:这个问题是在dendextend 1.9.0 中观察到的,但在报告错误后,包作者很快就修复了。 The new version 1.10.0 works perfectly fine with cluster and the clValid version from the CRAN.新版本 1.10.0 与cluster和 CRAN 的clValid版本完美配合。 It can be installed via : devtools::install_github("talgalili/dendextend")它可以通过以下方式安装: devtools::install_github("talgalili/dendextend")

This is the best solution now.这是目前最好的解决方案。 I let here the rest of my initial answer below for the archives only.我在下面只为档案提供我最初的答案的其余部分。


Some code to test that (everything works fine without dendextend but loading dendextend triggers the error message :一些用于测试的代码(在没有dendextend情况下一切正常,但加载dendextend会触发错误消息:

# detach(package:dendextend)
# library(dendextend)
# 
library(cluster)
d <- iris[,-5]
cl <- diana(dist(d))
cutree(cl, 3)
cl <- agnes(dist(d))
cutree(cl, 3)

library(clValid)
intern <- clValid(d, 2:10,
                  clMethods = c("hierarchical", "kmeans", "diana", "fanny",
                                "model", "pam", "agnes"),
                  method = "ward", validation = "internal")

Sadly clValid seems to be orphaned so it is not possible to ask the developer to change the code (or am I wrong ?).可悲的是clValid似乎是孤立的,因此不可能要求开发人员更改代码(或者我错了吗?)。

Solutions :解决方案:

  • do not use dendextend and clValid at the same time不要同时使用dendextendclValid
  • do not use agnes and diana in the clMethods argument of clValid不使用agnesdianaclMethods的说法clValid
  • I have forked the clValid github repository (from CRAN) and made the small changes necessary in the code.我已经分叉了clValid github 存储库(来自 CRAN)并在代码中进行了必要的小改动。 You can install this version with devtools::install_github("GillesSanMartin/clValid") .您可以使用devtools::install_github("GillesSanMartin/clValid")安装此版本。 It works for me also when dendextend is loaded.当加载dendextend时,它也适用于我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM