1

I have a data frame of p-values. Other than p-values it has some zero entries also.

data

     V1          V3          V4          V5          V6          V7        
1  ADAM32       0.001           0           0           0           0      
2  ADAM32       0.001        0.65       0.001       0.001        0.65   
3  ADAM32        0.65           0           0           0           0      
4    CCL5    0.000491    0.000491    0.000491           0           0      
5   CILP2 0.500000024 0.500000024 0.500000024           0           0      
6   EPHB3    0.000562    0.000562    0.000562    0.000562    0.000562      
7   EPHB3    0.000562           0           0           0           0      
8  GUCA1A    0.002006    0.602006    0.002006    0.602006    0.002006      
9  GUCA1A    0.602006           0           0           0           0      
10  HSPA6    0.000322    0.000322    0.000322    0.000322    0.000322      
11  HSPA6    0.000322           0           0           0           0      
12  MAPK1       0.002       0.002       0.002           0           0      

I use the following code to apply Fisher's method to combine the p-values of each row.

    ## Fisher's Method 
    Fisher.test <- function(p) {  
      Xsq <- -2*sum(log(p))
      p.val <- pchisq(Xsq, df = 2*length(p), lower.tail = FALSE)
      return(c(Xsq = Xsq, p.value = p.val))

    }

   for(k in 1 : nrow(data))
   {
     p <- as.numeric(data[j,-1])
     fisher <- Fisher.test(p)
     print(fisher)
   }

I want to skip zeros from adding to the row-sum, as it leads to an infinite value after the log transformation of the p-value.

josliber
  • 43,891
  • 12
  • 98
  • 133
Agaz Wani
  • 5,514
  • 8
  • 42
  • 62

1 Answers1

2

Use apply for more concise writting:

apply(df, 1, function(u) {x=as.numeric(u[-1]);Fisher.test(x[x!=0])})

On the first 4 lines it returns:

#            [,1]         [,2]      [,3]         [,4]
#Xsq     13.81551 4.316966e+01 0.8615658 4.571440e+01
#p.value  0.00100 4.637400e-06 0.6500000 3.374549e-08

Even if the best way would be to handle into your function the case when a vector with 0 is given (and also full of 0).

Colonel Beauvel
  • 30,423
  • 11
  • 47
  • 87
  • Can u please brief about function(u) – Agaz Wani Mar 24 '15 at 10:54
  • The function is just taking as argument a row, `u` which is a vector of character, convert element `V3` to `V7` as numeric , remove out the `0` and give this filtered vector to your function. `apply` enables to proceed like this for each row (argument `1`) of your `data.frame`. – Colonel Beauvel Mar 24 '15 at 10:56