相關(guān)性計(jì)算

計(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)行篩選。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容