簡體   English   中英

通過所有唯一對迭代Pearsons R相關

[英]Iterating Pearsons R Correlation through all unique pairs

如果我有一個包含7列或任意數量列的輸入文件,並且每個列中都有許多值,並且我想對所有唯一對(AB和BA相同)的列運行關聯,而不必進入並為每個可能的對做cor.test(column$A, Column$B)如何在R中做到這一點?

示例數據:

A    B    C    D
1    2    2    3
3    2    2    1
5    2    4    3 
5    2    3    3

在這種情況下,A,B,C,D是不同的列,我想對唯一對進行所有可能的關聯,其中AB和BA視為同一對,就像DA和AD是同一對。

你可以試試:

cor(df, use="complete.obs", method="kendall") #or whichever method fits you

要么:

#this gives significance levels also
library(Hmisc)
rcorr(df, type="pearson") # type can be pearson or spearman

#or as matrix
rcorr(as.matrix(df))

如果這樣做不起作用,請嘗試創建列向量列表並遍歷所有內容(我將嘗試在edit中提供示例)

希望這可以幫助

暫無
暫無

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

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