简体   繁体   English

R 树状图故障中的热图 function

[英]Heatmap function in R dendrogram failure

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.如果我不包括 distfun,那么一切都非常好,并且对 hclust function 有响应。 Any advice would be greatly appreicated.任何建议将不胜感激。

The standard call to dist computes the distance between the rows of the matrix provided, cor computes the correlation between columns of the provided matrix, so the above example to work, you need to transpose the matrix: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))

should work.应该管用。 If you use a square matrix, you'll get code that works, but it won't be calculating what you think it is.如果您使用方阵,您将获得有效的代码,但它不会计算您认为的内容。

This is not reproducible yet...这还不能重现...

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

works for me.为我工作。 I don't know what redgreen or data.test.factors are.我不知道redgreendata.test.factors是什么。

Have you tried debug(heatmap.2) or options(error=recover) (or traceback() , although it's unlikely to be useful on its own) to try to track down the precise location of the error?您是否尝试过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  

Building on Ben Bolker's reply, your code seems to work if TEST is an n×n matrix and data.test.factors is a vector of n integers.基于 Ben Bolker 的回复,如果TEST是 n×n 矩阵并且data.test.factors是 n 个整数的向量,您的代码似乎可以工作。 So for example starting with所以例如从

 n1 <- 5
 n2 <- 5
 n3 <- 5
 TEST <- matrix(runif(n1*n2), nrow=n1)
 data.test.factors <- sample(n3)

then your code will work.那么您的代码将起作用。 However if n1 and n2 are different then you will get the error row dendrogram ordering gave index of wrong length , while if they are the same but n3 is different or data.test.factors has non-integers then you will get the error 'ColSideColors' must be a character vector of length ncol(x) .但是,如果n1n2不同,那么您将得到错误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.

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