0

I am intersecting two files and afterwards doing a fisher test and an enrichment test on the results. However after running the fisher test there is an error which I do not understand.

> ee=c()
> E=c()
> for (e in 1: length(conditions))
+ {
+   for(i in 1: length(view))
+   {
+     A=length(na.omit(intersect(conditions[,e], view[,i])))
+     B=length(na.omit(intersect(conditions[,1], view[,i])))
+     C=length(na.omit(conditions[,e]))
+     D=length(na.omit(conditions[,1]))
+     ee=c(ee, fisher.test(matrix(c(A,B-A,C-A,A-B-C+D),nrow=2,ncol=2)
+                          ,alternative="two.sided")$p.val)                                     
+     E=c(E, (A/B) /  ((C-A)/(D-B))) 

+ } + } Error in fisher.test(matrix(c(A, B - A, C - A, A - B - C + D), nrow = 2, : all entries of 'x' must be nonnegative and finite

ee

    [1] 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00                                      1.000000e+00 1.000000e+00
      [8] 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 2.429018e-05         1.572763e-01 1.000000e+00
    [15] 3.620512e-03 6.605189e-01 3.930938e-01 7.564593e-01 8.356520e-01    8.354842e-01 8.718355e-01
         [22] 1.000000e+00 7.174337e-01 1.813913e-01 3.480816e-01 9.189262e-02 8.892926e-01 6.528839e-02
         [29] 1.000000e+00 8.452332e-01 1.000000e+00 1.000000e+00 1.000000e+00

E

  [1] 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000       1.0000000 1.0000000 1.0000000
   [11]       NaN 0.2527881 0.6250381 0.9075342 2.1028830 0.8772727 0.6801843 1.1282051 0.8698752 0.9007353
   [21] 0.9247312       NaN 0.8624535 1.3294461 0.5018939 0.5030426 1.0376344 1.5870968 0.9445438 0.9242424
   [31] 0.9570313 0.9907834       NaN

The "conditions" dataframe contains 10 columns, and the "view" dataframe contains 11 columns. After intersection I would expect a 110 results to come out of the fisher test and enrichment caculation (E=c(E, (A/B) / ((C-A)/(D-B))) ) ,not 33 as in the output. There are NA's in both the dataframes but the na.omit should take care of that, all other values are just positive numerical values.

Help would be really appreciated.

  • The `E` and `ee` results that you are seeing are the results from the aggregated last iteration before the error. That is why they are not all there. While looping through `view` and `conditions`, one of the values fed into the matrix call `matrix(c(A,B-A` is causing a problem. Since R stopped at the error. You can check the values of all variables for off results. Someone can find a good general answer on debugging code. – Pierre L Jun 19 '15 at 14:27
  • Yes, this seems to be the case. The values fed into the matrix originate in dataframses that were imported from excel, they are csv files and look fine both in excel and in R (only positive numbers and NA's). Is there anything in particular I should be aware of when feeding data into a fisher test? – Jakobijn Strobbe Jun 22 '15 at 08:43
  • You haven't provided a reproducible example. There is very little help that I can give with imaginary data. Simplify your dataset to 10 rows that look like the basic structure of your data. – Pierre L Jun 22 '15 at 08:50

0 Answers0