-2

I have next SNPs data.frame structure

> str(SNPs)
'data.frame':   1703 obs. of  4 variables:
 $ group: Factor w/ 2 levels "A","B": 1 1 1 1 1 1 1 1 1 1 ...
 $ rs1  : Factor w/ 3 levels "D/D","I/D","I/I": 1 1 2 3 3 2 1 1 1 1 ...
 $ rs2  : Factor w/ 3 levels "a/a","a/b","b/b": 3 3 2 3 3 2 2 3 3 2 ...
 $ rs3  : Factor w/ 3 levels "G/G","G/T","T/T": 2 1 2 1 1 3 1 1 2 1 ...
 ...other rs


> head(SNPs)
  group rs1 rs2 rs3 ...other rs
1     A D/D b/b G/T
2     A D/D b/b G/G
3     A I/D a/b G/T
4     A I/I b/b G/G
5     A I/I b/b G/G
6     A I/D a/b T/T

For example, I noticed that rs5 4b/4a and rs6 G/G in group A very often occur together (see below). In group B they very often occur together too. So I want to know - is it statistical regularity or not.

I can create table with all pairs in both groups

> SNPs$rs5_rs6 <- paste(SNPs$rs5, SNPs$rs6)
> tmp <- table(SNPs$rs5_rs6, SNPs$group)
> tmp

              A   B
  4a/4a G/G   1  20
  4b/4a G/G  31  83
  4b/4a G/T  14  51
  4b/4a T/T   1   0
  4b/4b G/G  37 106
  4b/4b G/T  35 119
  4b/4b T/T  11  31

So, now I need compare (find p-value) group A and group B: 4a/4a G/G in group A vs 4a/4a G/G in group B, 4b/4a G/G in group A vs 4b/4a G/G in group B, 4b/4a G/T in group A vs 4b/4a G/T in group B and etc. Only this pairs/

How can I do that?

autumnrustle
  • 595
  • 1
  • 10
  • 21

1 Answers1

0

If you want proportion test (H0 = 0.5) for every row you can use mapply function as below:

prop.test can be used for testing the null that the proportions (probabilities of success) in several groups are the same, or that they equal certain given values.

str <- "x y A B
4a/4a G/G   1  20
4b/4a G/G  31  83
4b/4a G/T  14  51
4b/4a T/T   1   0
4b/4b G/G  37 106
4b/4b G/T  35 119
4b/4b T/T  11  31"

df <- read.table(text = str, header = TRUE)

df$p_value <- mapply(function(x, y) prop.test(x, x + y, conf.level = 0.95)$p.value, df$A, df$B)
df

Output:

      x   y  A   B      p_value
1 4a/4a G/G  1  20 8.568298e-05
2 4b/4a G/G 31  83 1.782949e-06
3 4b/4a G/T 14  51 7.997514e-06
4 4b/4a T/T  1   0 1.000000e+00
5 4b/4b G/G 37 106 1.297106e-08
6 4b/4b G/T 35 119 2.257307e-11
7 4b/4b T/T 11  31 3.370431e-03
Artem
  • 3,304
  • 3
  • 18
  • 41