[英]Heatmap function in R dendrogram failure
对于我的生活,我无法理解为什么这种方法会失败,我真的很感激这里有一双额外的眼睛:
heatmap.2(TEST,trace="none",density="none",scale="row",
ColSideColors=c("red","blue")[data.test.factors],
col=redgreen,labRow="",
hclustfun=function(x) hclust(x,method="complete"),
distfun=function(x) as.dist((1 - cor(x))/2))
我得到的错误是:行树状图排序给出了错误长度的索引
如果我不包括 distfun,那么一切都非常好,并且对 hclust function 有响应。 任何建议将不胜感激。
对dist
的标准调用计算提供的矩阵的行之间的距离,cor 计算提供的矩阵的列之间的相关性,所以上面的例子工作,你需要转置矩阵:
heatmap.2(TEST,trace="none",density="none",scale="row",
ColSideColors=c("red","blue")[data.test.factors],
col=redgreen,labRow="",
hclustfun=function(x) hclust(x,method="complete"),
distfun=function(x) as.dist((1 - cor( t(x) ))/2))
应该管用。 如果您使用方阵,您将获得有效的代码,但它不会计算您认为的内容。
这还不能重现...
TEST <- matrix(runif(100),nrow=10)
heatmap.2(TEST, trace="none", density="none",
scale="row",
labRow="",
hclust=function(x) hclust(x,method="complete"),
distfun=function(x) as.dist((1-cor(x))/2))
为我工作。 我不知道redgreen
或data.test.factors
是什么。
您是否尝试过debug(heatmap.2)
或options(error=recover)
(或traceback()
,尽管它本身不太可能有用)来尝试追踪错误的精确位置?
> sessionInfo()
R version 2.13.0 alpha (2011-03-18 r54865)
Platform: i686-pc-linux-gnu (32-bit)
...
other attached packages:
[1] gplots_2.8.0 caTools_1.12 bitops_1.0-4.1 gdata_2.8.2 gtools_2.6.2
基于 Ben Bolker 的回复,如果TEST
是 n×n 矩阵并且data.test.factors
是 n 个整数的向量,您的代码似乎可以工作。 所以例如从
n1 <- 5
n2 <- 5
n3 <- 5
TEST <- matrix(runif(n1*n2), nrow=n1)
data.test.factors <- sample(n3)
那么您的代码将起作用。 但是,如果n1
和n2
不同,那么您将得到错误row dendrogram ordering gave index of wrong length
,而如果它们相同但n3
不同或data.test.factors
具有非整数,那么您将得到错误'ColSideColors' must be a character vector of length ncol(x)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.