2

For the life of me I cannot understand why this method is failing, I would really appreciate an additional set of eyes here:

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))  

The error that I get is: row dendrogram ordering gave index of wrong length

If I don't include the distfun, everything works really well and is responsive to the hclust function. Any advice would be greatly appreicated.

4

3 回答 3

3

标准调用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))

应该管用。如果您使用方阵,您将获得有效的代码,但它不会计算您认为的内容。

于 2013-03-12T15:20:28.430 回答
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  
于 2011-07-15T23:56:24.893 回答
1

基于 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)

那么您的代码将起作用。但是,如果n1n2不同,那么您将收到错误row dendrogram ordering gave index of wrong length,而如果它们相同但n3不同或data.test.factors具有非整数,那么您将收到错误'ColSideColors' must be a character vector of length ncol(x)

于 2011-07-16T08:58:59.430 回答