[英]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
包的某些函数生成的对象,如diana
和agnes
(而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 :解决方案:
dendextend
and clValid
at the same timedendextend
和clValid
agnes
and diana
in the clMethods
argument of clValid
agnes
和diana
在clMethods
的说法clValid
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.