Question: Dear all:
I want to obtain chi-square statistics for following data by element wise. My apology to ask this statistical question from this community. However, my data contains list of overlap's significance score of 3 GRanges objects, I want to get its global score by element-wise. How can I get this in R?

#This is the data that I want to get its global score by element wise:

[[1]]
NumericList of length 7
[[1]] 1e-22
[[2]] 1e-19
[[3]] 1e-18
[[4]] 1e-16
[[5]] 1e-24
[[6]] 1e-20
[[7]] 1e-15

[[2]]
NumericList of length 7
[[1]] 1e-24
[[2]] 1e-24
[[3]] 1e-20
[[4]] 1e-25
[[5]] 0.1
[[6]] 1e-19
[[7]] 1e-18

[[3]]
NumericList of length 7
[[1]] 1e-11
[[2]] 1e-11
[[3]] 1e-10
[[4]] numeric(0)
[[5]] numeric(0)
[[6]] 1e-15
[[7]] numeric(0)

if you wonder third list element contains numeric(0), which refers to non-overlapped regions, so I can replace it with zero:

li.3 <- <- lapply(li.3, function(x) {
res <- ifelse(length(x)>0, x, 0)
})

# this is reproducible example :

data <- DataFrame(
v1=c(1e-22,1e-19,1e-18,1e-16,1e-24,1e-20, 1e-15),
v2=c(1e-24,1e-24,1e-20,1e-25,0.1,1e-19,1e-18),
v3=c(1e-11,1e-11,1e-10,numeric(0),numeric(0),1e-15,numeric(0)))

#my desired output something like (just example by element wise) :
global fisher score of `(1e-22, 1e-24, 1e-11)` = ?
global fisher score of `(1e-19, 1e-24, 1e-11)` = ?
...
global fisher score of `(1e-24, 1e-01, numeric(0))` = ?

I want to get global score by element wise. How can I get this in R? Alternatively, I also prefer to see fisher exact test result for above data. I will be grateful if anyone can give me any idea for doing this. Thanks a lot

Answer: You have a data frame with three columns:

> data
DataFrame with 7 rows and 3 columns
v1 v2 v3

1 1e-22 1e-24 1e-11
2 1e-19 1e-24 1e-11
3 1e-18 1e-20 1e-10
4 1e-16 1e-25 0e+00
5 1e-24 1e-01 0e+00
6 1e-20 1e-19 1e-15
7 1e-15 1e-18 0e+00

What confuses me is that this dataframe seems to contain p-values already. So what do you want to calculate exactly?

You may combine p-values, assuming they are independent, using different approaches. The simplest is just by taking their mean (see [When combining p-values, why not just averaging?][1] )

> data$global = apply(data[1:3], 1, mean)
> data
DataFrame with 7 rows and 4 columns
v1 v2 v3 global

1 1e-22 1e-24 1e-11 3.333333e-12
2 1e-19 1e-24 1e-11 3.333333e-12
3 1e-18 1e-20 1e-10 3.333333e-11
4 1e-16 1e-25 0e+00 3.333333e-17
5 1e-24 1e-01 0e+00 3.333333e-02
6 1e-20 1e-19 1e-15 3.333700e-16
7 1e-15 1e-18 0e+00 3.336667e-16
>

More accurate methods to combine p-values would include Fisher's method. See for example http://stats.stackexchange.com/questions/168181/r-package-for-combining-p-values-using-fishers-or-stouffers-method for some R packages to do it.

For example:

> library(metap)
> data$global = apply(data[1:3], 1, function(df) sumlog(df)$p)
Warning messages:
1: In sumlog(df) : Some studies omitted
2: In sumlog(df) : Some studies omitted
3: In sumlog(df) : Some studies omitted
> data
DataFrame with 7 rows and 4 columns
v1 v2 v3 global

1 1e-22 1e-24 1e-11 8.745181e-54
2 1e-19 1e-24 1e-11 7.855507e-51
3 1e-18 1e-20 1e-10 6.219311e-45
4 1e-16 1e-25 0e+00 9.540599e-40
5 1e-24 1e-01 0e+00 5.856463e-24
6 1e-20 1e-19 1e-15 7.855507e-51
7 1e-15 1e-18 0e+00 7.698531e-32
> sumlog(c(1e-22, 1e-24, 1e-11))
chisq = 262.4947 with df = 6 p = 8.745181e-54
>

[1]: http://stats.stackexchange.com/questions/78596/when-combining-p-values-why-not-just-averaging