R 使用数据帧列中的值进行比例测试

R 使用数据帧列中的值进行比例测试,r,testing,R,Testing,所以我被一些看似基本的东西困住了,但无论如何。我得到了下面的数据帧(Dat.f),我需要对Posgain.vector和Neggain.vector运行一个comportions.test(卡方检验),并提取P值 使用公式prop.test 如果以第一行为例手动完成,结果将是 P<-prop.test(x=c(4,4), n=c(16,10)[2] Posgain.vector Freq Neggain.vector Freq.1 PosRef NegRef 1

所以我被一些看似基本的东西困住了,但无论如何。我得到了下面的数据帧(Dat.f),我需要对Posgain.vector和Neggain.vector运行一个comportions.test(卡方检验),并提取P值 使用公式prop.test

如果以第一行为例手动完成,结果将是

 P<-prop.test(x=c(4,4), n=c(16,10)[2]

  Posgain.vector Freq Neggain.vector Freq.1 PosRef NegRef
1           A1BG    4           A1BG      4     16     10
2       A1BG-AS1    4       A1BG-AS1      4     16     10
3           A1CF    4           A1CF      1     16     10
4            A2M    1            A2M      1     16     10
5        A2M-AS1    1        A2M-AS1      1     16     10
6          A2ML1    1          A2ML1      1     16     10

P

非常类似于@agstudy,但提取P.value:

df = data.frame(Posgain.vector=c("A1BG", "A1BG-AS1", "A1CF", "A2M", "A2M-AS1", "A2ML1"),
                Freq = c(4, 4, 4, 1, 1, 1),
                Neggain.vector=c("A1BG", "A1BG-AS1", "A1CF", "A2M", "A2M-AS1", "A2ML1"),
                Freq.1 = c(4, 4, 1, 1, 1, 1),
                PosRef = rep(16, 6),
                NegRef = rep(10, 6))
apply(df[, c(2,4)], 1, function(row) prop.test(x=c(row[1], row[2]), n=c(16, 10))$p.value)

# [1] 0.7117401 0.7117401 0.6652053 1.0000000 1.0000000 1.0000000