简体   繁体   English

fisher.test使用R

[英]fisher.test using R

I am trying do the Fisher Exact Test for more than 400 dates. 我正在尝试进行超过400个日期的Fisher精确测试。 The Fisher Exact Test works 2x2 possibilities. Fisher精确测试有2x2的可能性。 This test is to many used in molecular markers and genetics studies. 该测试适用于许多分子标记和遗传学研究。 So, if I have to many dates, became impossible make all possibilities one to one combination of markers. 因此,如果我有很多约会,就不可能将所有可能性一对一地组合在一起。

Analysis code in R: R中的分析代码:

alelo1<-data[,1]
alelo2<-data[,2]
fisher.test(alelo1,alelo2)$p.valeu

I tried do using the: 我尝试使用以下方法:

(for i in)

But I did not had success. 但是我没有成功。 How could I do it automatically using R?? 我如何使用R自动执行此操作?

Tnks! Tnks!

Is a bit hard to tell from the question what you want, but if I was able to decipher something I think you want to create 2X2 matrix combinations from the columns of a 2X400 matrix. 从这个问题很难说出您想要什么,但是如果我能够解密某些内容,我想您想从2X400矩阵的列中创建2X2矩阵组合。

So you would have 79800 combinations? 因此,您将拥有79800种组合? I think. 我认为。

choose(400,2) = 79800

I guess for the fisher.test i,j is the same as j,i and that i=j doesn't make much sense, so 我猜想是fisher.test i,j与j,i相同,并且i = j没有多大意义,所以

I would start by doing a function: 我将从做一个函数开始:

alelos = function(i,j){
alleys= matrix(c(df[,i],df[,j]),nrow=2,byrow=F)
#df is the 2X400 matrix, called data in the question
return(fisher.test(alleys)$p.value)
}

Then try the loops with for (i in 1:400) and a while perhaps? 然后尝试使用for(1:400中的i)循环并持续一段时间? or something that makes a triangular matrix with the results. 或使结果成为三角形矩阵的东西。 Such as: 如:

I will give you an example with a vector of 10 columns. 我将为您提供一个包含10列向量的示例。

same thing should work for 400. 同样的东西应该可以工作400。

set.seed(4)
df= matrix(c(sample(1:100,10,replace=T),sample(1:100,10,replace=T)),nrow=2)


resultmatrix = matrix(0,10,10)
#or 10x9 if you prefer

for(i in 10:1){
  j=1
while(i > j){
  resultmatrix[i,j]= alelos(i,j)

j=j+1
}
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM