計(jì)算大量指標(biāo)間的相關(guān)性,并以熱圖形式展示。
參考:http://www.sthda.com/english/wiki/correlation-matrix-a-quick-start-guide-to-analyze-format-and-visualize-a-correlation-matrix-using-r-software 【超贊的資料】

相關(guān)性熱圖
#計(jì)算相關(guān)性
require(Hmisc)
require(pheatmap)
d=read.table("example",header=T,row.names = 1)
head(d)
# index1 index2 index3 index4 index5 index6 index7 index8 index9 index10
#sample1 134 3.60 29.3 9.0 55.8 2.7 0.4 1.05 0.32 2.01
#sample2 218 2.46 40.0 9.8 44.1 2.5 0.3 0.98 0.24 1.08
#sample3 185 3.74 46.7 6.5 37.5 5.7 1.1 1.75 0.24 1.40
#sample4 220 7.44 33.5 6.9 55.5 2.0 0.2 2.49 0.52 4.13
#sample5 228 4.23 37.4 4.5 53.9 1.3 0.3 1.58 0.19 2.28
#sample6 226 5.36 33.9 7.6 53.1 2.3 0.3 1.82 0.41 2.85
#index之間的相關(guān)性:得到相關(guān)性矩陣,可作熱圖/直接輸出
res<-cor(d, use="pairwise.complete.obs") #默認(rèn)method為pearson,可設(shè)置其他計(jì)算方法;針對(duì)缺失數(shù)據(jù)有不同處理方式
pheatmap(res)
#按列輸出(方便篩選)
res2 <- rcorr(as.matrix(d))
out=flattenCorrMatrix(res2$r, res2$P)
head(out)
# row column cor p
#1 index1 index2 0.53579901 0.002276657
#2 index1 index3 -0.06037896 0.751284491
#3 index2 index3 -0.30683542 0.099095706
#4 index1 index4 -0.01099476 0.954016664
#5 index2 index4 -0.14452340 0.446080828
#6 index3 index4 0.30426964 0.102098355
熱圖是根據(jù)相關(guān)性值做的,沒(méi)有體現(xiàn)顯著性值(p value),一般需要根據(jù)p值來(lái)進(jìn)行篩選。