0
votes

I have data as shown below:

chr1    876499  A   517    G    948 A   353  G  964
chr1    877715  C   1166   G    883 C   555  G  944
chr1    877831  T   0      C    1   T   0    C  1
chr1    878314  G   933    C    666 G   89   C  106
chr1    878331  C   983    T    166 C   994  T  505

I would like to do fisher exact test, by making a matrix from columns 4,6,8 and 10 in the below shown way:

For example for first row:

       u    v
X   517   948
Y   353   964

It should calculate the Fisher-exact p-value, and add it as a new column to each row. Since im novice to R i do not have any code. Any help is valuable.

Thanks.

1
Have you tried anything yet, or searched for examples of how to perform this test in R, or typed ?fisher.test into your R console?Steve Kern
yes, but haven't been successful in making the matrix as shown.chas
@rawr Thanks. could you let me know assuming count data in the above data frame?chas

1 Answers

1
votes

Try:

 d.frm <- read.table(textConnection("
 chr1    876499  A   517    G    948 A   353  G  964
 chr1    877715  C   1166   G    883 C   555  G  944
 chr1    877831  T   0      C    1   T   0    C  1
 chr1    878314  G   933    C    666 G   89   C  106
 chr1    878331  C   983    T    166 C   994  T  505
 "))

d.frm$pval <- apply(as.matrix(d.frm[, c(4,6,8,10)]), 1, 
                    function(x) fisher.test(matrix(x, nrow=2))$p.value)