首页 > 解决方案 > 使用相同距离的意外聚类 (pearson)

问题描述

我正在使用一些虚拟数据来测试基于相关距离的聚类(pearson)。我以两种方式计算 pearson 相关性,一种在pheatmap函数内部,另一种在 using 外部cor(),两种方式我都希望检索相同的结果。

在玩虚拟随机生成的数据时,大多数时候集群是相同的,但有时差异足以注意到集群之间的差异(即执行之间不同集群中的样本)。

我错过了什么?为什么集群并不总是相同的?

我只对聚类列感兴趣。

# Random matrix generation
x <- rep(c(1:100, 100:1), 100)
mtx <- matrix(x, ncol = 10, nrow = 100)
noise <- matrix(rnorm(10 * 100), ncol = 10, nrow = 100)
mtx <- mtx * noise

rownames(mtx) <- paste("Genes_", 1:100, sep = "")
colnames(mtx) <- paste("Patient_", 1:10, sep = "")


library("pheatmap")

# Clustering based on pheatmap correlation = pearson (execution type 1)
pheatmap(mtx,
         clustering_distance_cols = "correlation",
         clustering_method = "complete",
         show_rownames = FALSE,
         show_colnames = TRUE,
         main = "correlation",
         cluster_rows = FALSE)

# Calculate correlation prior pheatmap function (execution type 2)
pheatmap(cor(mtx, method = "pearson"),
         clustering_distance_rows = "none",
         clustering_method = "complete",
         show_rownames = FALSE,
         show_colnames = TRUE,
         main = "pearson",
         cluster_rows = FALSE)

标签: rcorrelationpheatmappearson

解决方案


推荐阅读