Reputation: 3
I am trying do the Fisher Exact Test for more than 400 dates. The Fisher Exact Test works 2x2 possibilities. 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:
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??
Tnks!
Upvotes: 0
Views: 608
Reputation: 4826
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.
So you would have 79800 combinations? 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
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? or something that makes a triangular matrix with the results. Such as:
I will give you an example with a vector of 10 columns.
same thing should work for 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
}
}
Upvotes: 1