gpt4 book ai didi

r - 使用 PIL 逊距离的微阵列数据热图

转载 作者:行者123 更新时间:2023-12-01 21:58:05 25 4
gpt4 key购买 nike

我一直在尝试在 R 中为一些微阵列数据生成热图,并且在很大程度上已经成功地根据在线指令生成了一个热图,但它并没有完全达到我想要的效果。我想要的是基于 PIL 逊距离而不是欧几里德距离来聚类数据,但我遇到了一些困难。

使用 heatmap2(来自 gplots 包),我使用以下代码来制作初始热图:

heatmap.2(Test402,trace="none",density="none",scale="row", ColSideColors=c("red","blue")   [data.test.factors],col=redgreen,labRow="",hclustfun=function(x) hclust(x,method="complete"))

Test402 是一个包含 402 行(基因)和 31 列(患者)的矩阵,data.test.factors 是每个患者所属结果组的指标。使用 hclustfun 在这里工作得很好,并且热图似乎对方法和整体工作的变化做出了响应。问题是,聚类距离都是欧氏距离,我想将其更改为 PIL 逊距离。所以我尝试以下操作:

heatmap.2(Test402,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) )

以上命令失败。那是因为Test402 needs to be a square matrix.因此,考虑到一些其他建议,我尝试了以下方法:

cU = cor(Test402)
heatmap.2(cU,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-x)/2) )

这可行,但问题就在这里。热图现在仅显示相关性,而不是 TEST402 中的原始表达式值。这不是我想要的!我要this ,我只希望树状图以不同的方式聚类,我不想更改热图中实际表示的数据!这可能吗?

最佳答案

好吧...我认为您只是对 cordist 的操作方式感到困惑。来自 dist 的文档:

This function computes and returns the distance matrix computed by using the specified 
distance measure to compute the distances between the rows of a data matrix.

来自 cor 的文档:

If x and y are matrices then the covariances (or correlations) 
between the columns of x and the columns of y are computed.

看出区别了吗? dist (和 dist 对象,这是 heatmap.2 假设它得到的)假设您已经计算了 之间的距离行,而使用cor时,您实际上是在计算之间的距离。在距离函数中添加一个简单的转置可以让这个(非方形)示例为我运行:

TEST <- matrix(runif(100),nrow=20)
heatmap.2(t(TEST), trace="none", density="none",
scale="row",
labRow="",
hclust=function(x) hclust(x,method="complete"),
distfun=function(x) as.dist((1-cor(t(x)))/2))

关于r - 使用 PIL 逊距离的微阵列数据热图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6719747/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com