admin管理员组文章数量:1123193
I am trying to figure out the way to assess similarity between a few vectors containing gene names. I have only gene names for this so I wanted to use Jaccard dissimilarity and then convert it it similarity and plot a heatmap of the results.
Here is an example of what I am trying:
library(vegan)
library(pheatmap)
data <- matrix(c(1, 0, 1,
1, 1, 0,
0, 1, 1,
1, 1, 1),
ncol = 3, byrow = TRUE)
rownames(data) <- c("Gene1", "Gene2", "Gene3", "Gene4")
colnames(data) <- c("Sample1", "Sample2", "Sample3")
dissimilarity <- vegdist(data, method = "jaccard")
similarity <- 1 - dissimilarity
pheatmap(as.matrix(dissimilarity), main = "Jaccard Dissimilarity")
pheatmap(as.matrix(similarity), main = "Jaccard Similarity")
heatmap(as.matrix(similarity), main = "Jaccard Similarity")
heatmap(as.matrix(dissimilarity), main = "Jaccard Dissimilarity")
The code works fine for "dissimilarity" in which case diagonals are 0 as the samples are have no distance to themselves. However, converting to "similarity" I expect the diagonals to be 1 (because 1-0=1 and that the similarity between the sample and itself is full) but the plots show that diagonal is 0 for both "dissimilarity" and "similarity".
I have a feeling it is because the vegdist()
function leaves some parts of the matrix empty and then both heatmap()
and pheatmap()
automatically fill those missing parts with 0s but I am not sure how to fix it without redoing the matrices resulting from vegdist()
.
Is my approach to calculate "similarity" from ""dissimilarity" wrong? How can I fix it and have correct values and colors in diagonals without manually changing the matrices that are plotted?
本文标签: rHeatmap diagonals generated from vegdist are wrong for similarityStack Overflow
版权声明:本文标题:r - Heatmap diagonals generated from vegdist are wrong for similarity - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736551110a1944512.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论