gpt4 book ai didi

r - 在Heatmap.2中设置距离矩阵和聚类方法

转载 作者:行者123 更新时间:2023-12-03 20:01:14 33 4
gpt4 key购买 nike

heatmap.2默认为dist用于计算距离矩阵,hclust用于聚类。
现在有人可以将dist设置为使用欧几里得方法,而hclust设置为质心方法吗?
我提供了下面的可编译代码示例。
我试过了:distfun = dist(method =“ euclidean”),
但这不起作用。有任何想法吗?

library("gplots")
library("RColorBrewer")

test <- matrix(c(79,38.6,30.2,10.8,22,
81,37.7,28.4,9.7,19.9,
82,36.2,26.8,9.8,20.9,
74,29.9,17.2,6.1,13.9,
81,37.4,20.5,6.7,14.6),ncol=5,byrow=TRUE)
colnames(test) <- c("18:0","18:1","18:2","18:3","20:0")
rownames(test) <- c("Sample 1","Sample 2","Sample 3", "Sample 4","Sample 5")
test <- as.table(test)
mat=data.matrix(test)

heatmap.2(mat,
dendrogram="row",
Rowv=TRUE,
Colv=NULL,
distfun = dist,
hclustfun = hclust,
xlab = "Lipid Species",
ylab = NULL,
colsep=c(1),
sepcolor="black",
key=TRUE,
keysize=1,
trace="none",
density.info=c("none"),
margins=c(8, 12),
col=bluered
)

最佳答案

浏览heatmap.2的代码,我相当确定默认值是使用dist,而默认值是使用欧几里德距离。

您尝试传递distfun = dist(method = 'euclidean')无效的原因是distfun(和hclustfun)应该只是函数的名称。因此,如果要更改默认值并传递参数,则需要编写如下包装函数:

heatmap.2(...,hclustfun = function(x) hclust(x,method = 'centroid'),...)


正如我提到的,我可以肯定 heatmap.2默认使用欧几里得距离,但是可以使用类似的解决方案来更改所使用的距离函数:

heatmap.2(...,distfun = function(x) dist(x,method = 'euclidean'),...)

关于r - 在Heatmap.2中设置距离矩阵和聚类方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6806762/

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