r - 使用相同距离的意外聚类 (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)
解决方案
推荐阅读
- c++ - 尝试在 C++ 中重载增量运算符
- node.js - serve 命令需要在 Angular 项目中运行,但找不到项目定义
- javascript - JavaScript 延迟对象 - 在 Promise 之后运行两个异步请求
- javascript - 在 kebab 情况下访问 JSON 字段(例如 some-value)
- ms-access - MS Access 如何计算过滤报告上的唯一记录或值
- python - 使用多个 if 语句加快代码的运行时间
- java - Java File.getCanonicalFile() 无法处理冒号':'
- java - 为什么 SimpleDateFormat 用错误的月份和日期解析日期?
- java - 如何删除Java中特定字符之间的子字符串?
- c# - 使用 aspnetcore 信号器作为 system.io 流阻塞