簡體   English   中英

corr.test() 結果問題

[英]Issue with corr.test() results

我正在運行 corr.test() 以使用以下代碼查看數據框中基因和細菌之間的潛在相關性:

spearman=cor.test(FullSet$counts.Bac, FullSet$counts.Gene, method="spearman", alternative=c("two.sided"))

我的數據框結構如下:

主題 名字.Bac 計數.Bac 姓名.基因 計數.基因
10℃ 芬戈迪亞 -2.07 CCL4 1.73
10℃ 芬戈迪亞 -2.07 CKAP4 6.7

我的數據框總共有大約 400 萬行,因為我正在針對 24 名患者的 33 種細菌測試大約 2000 個基因。

當我運行上面的代碼時,我得到以下結果:

Spearman's rank correlation rho

data:  FullSet$counts.Bac and FullSet$counts.Gene
S = 1.1501e+19, p-value = 8.368e-09
alternative hypothesis: true rho is not equal to 0
sample estimates:
         rho 
-0.002845856 

但是,我的目標是將結果作為矩陣獲得,其中包含單獨的測試結果和每次比較的 p.values,因此我可以使用 corrplot() 繪制結果。 做這個的最好方式是什么?

也許像這樣?
name.Bacname.Gene對數據進行分區,並在lapply循環中運行測試。 然后使用一系列sapply循環提取相關值,並使用cbind形成結果矩陣。

sp <- split(FullSet, list(FullSet$name.Bac, FullSet$name.Gene))
spearman_list <- lapply(sp, \(x) {
  cor.test(x$counts.Bac, x$counts.Gene, data = x, method = "spearman", alternative = "two.sided")
})

stat <- sapply(spearman_list, `[[`, 'statistic')
pval <- sapply(spearman_list, `[[`, 'p.value')

cbind(stat, pval)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM