pheatmap 默认距离度量 R

Sam*_*gen 4 r distance metric pheatmap

我需要使用“pheatmap”函数制作热图,使用 UPGMA 和 1-pearson 相关性作为距离度量。我的教授声称这是默认的距离度量,尽管在我的例子中它使用“欧几里德”作为距离度量。欧几里得和 1 - 皮尔逊相关性相同还是他错了?如果他错了,我如何为我的热图使用正确的距离度量?

我的意见

ph=pheatmap(avgreltlog10, color = colorRampPalette(rev(brewer.pal(n = 7, 
name = "RdYlBu")))(100), 
kmeans_k = NA, breaks = NA, border_color = "grey60",
cellwidth = 10, cellheight=10, scale = "none", cluster_rows=TRUE,
clustering_method = "average", cutree_rows = 4, cutree_cols= 2,)
Run Code Online (Sandbox Code Playgroud)

R输出

$tree_row

Call:
hclust(d = d, method = method)

Cluster method   : average 
Distance         : euclidean 
Number of objects: 65 


$tree_col

Call:
hclust(d = d, method = method)

Cluster method   : average 
Distance         : euclidean 
Number of objects: 10 
Run Code Online (Sandbox Code Playgroud)

Spl*_*Inf 5

您可以通过在终端中键入不带 () 的函数名称来轻松检查默认设置

>pheatmap
Run Code Online (Sandbox Code Playgroud)

如果这样做,您可以看到欧几里德被用作默认值:

... clustering_distance_rows = "euclidean", clustering_distance_cols = "euclidean", clustering_method = "complete", ...
Run Code Online (Sandbox Code Playgroud)

要使用 1-pearson 相关性,只需将其指定为这样:

cluster_rows = TRUE,
clustering_distance_rows = "correlation"
Run Code Online (Sandbox Code Playgroud)

它之所以有效,是因为如果您深入研究代码,您会发现它调用了 cluster_mat,它执行以下操作:

cluster_mat = function(mat, distance, method){
...
    if(distance[1] == "correlation"){
        d = as.dist(1 - cor(t(mat)))
    }
...
Run Code Online (Sandbox Code Playgroud)

更多信息参见官方文档。周围有太多的软件包,因此混淆它们并不罕见:)