从 R 中的数据帧计算平均成对皮尔逊相关系数



假设我有以下向量:

IDs_Complex_1 <- c("orangutan", "panda", "sloth", "mountain_gorilla", "dolphin", "snake")
IDs_Complex_2 <- c("bat", "penguin", "goat", "elephant", "tiger")

我想计算以下数据框中每个向量垂直采集的组织列中的值之间的成对皮尔逊相关系数。然后,我希望找到所有可能组合的平均PCC。

Complex_ID        Tissue_X Tissue_Y Tissue_Z
orangutan         5         6        7
panda             6         7        8
sloth             7         8        9
mountain_gorilla  100       60       50
dolphin           115       62       51
snake             130       59       67
bat               2         6        7
penguin           15        11       12
goat              22        23       86
elephant          14        22       109
tiger             0         1        7

因此,为了说明复杂 1 的这一点,我希望计算:

Pdf<- PCC of (5, 6, 7, 100, 115, 130) and (6, 7, 8, 60, 62, 59)
PCC_2 <- PCC of (5, 6, 7, 100, 115, 130) and (7, 8, 9, 50, 51, 67)
PCC_3 <- PCC of (6, 7, 8, 60, 62, 59) and (7, 8, 9, 50, 51, 67)

我想计算平均值

(PCC_1, PCC_2, PCC_3) = ?

但是,如果我有二十个左右的组织柱,其中会有20!/2!18!= 190个成对相关系数的组合(不重复(。我将如何编码?

非常感谢!

阿比盖尔

如果CC_1是你的 data.frame:

df = structure(list(Complex_ID = structure(c(6L, 7L, 9L, 5L, 2L, 10L, 
1L, 8L, 4L, 3L, 11L), .Label = c("bat", "dolphin", "elephant", 
"goat", "mountain_gorilla", "orangutan", "panda", "penguin", 
"sloth", "snake", "tiger"), class = "factor"), Tissue_X = c(5L, 
6L, 7L, 100L, 115L, 130L, 2L, 15L, 22L, 14L, 0L), Tissue_Y = c(6L, 
7L, 8L, 60L, 62L, 59L, 6L, 11L, 23L, 22L, 1L), Tissue_Z = c(7L, 
8L, 9L, 50L, 51L, 67L, 7L, 12L, 86L, 109L, 7L)), class = "data.frame", row.names = c(NA, 
-11L))

你可以做:

cor(df[,-1])
Tissue_X  Tissue_Y  Tissue_Z
Tissue_X 1.0000000 0.9748668 0.4119840
Tissue_Y 0.9748668 1.0000000 0.5440719
Tissue_Z 0.4119840 0.5440719 1.0000000

相关内容

  • 没有找到相关文章

最新更新