Question: Probability of gene list overlap
15
Nasir160 wrote:

Is this the correct way to calculate the probability of overlap occurring by chance between two lists of unregulated genes generated from two independent experiments on the same tissue using the same platform?

I am using R `phyper`.

``````phyper(q, m, n, k, lower.tail = FALSE, log.p = FALSE)
``````

where:
q=size of overlap-1;
m=number of upregulated genes in experiment #1;
n=(total number of genes on platform-m);
k=number of upregulated genes in experiment #2.

overlap R gene • 15k views
modified 2.2 years ago by Biostar ♦♦ 20 • written 8.7 years ago by Nasir160
2

Here is a good post on the stackexchange stats Q&A about hypergeometric for list overlap.

yes this is the correct way to do this.

Hello,

I just have a similar question: Can I use R phyper in the above way to calculate the probability of overlap occurring by chance between two lists of hit genes identified by two different algorithmsg on the same tissue?

Thank you very much!

I think yes, as long as the total number of genes is identical between both tries. Note that the probability is those of two independent random draws ('totally random'), that is maybe not such a good benchmark for a comparison of two algorithms.

are the 2 lists from the same cell type?

3
Michael Dondrup47k wrote:

Yes, this seems correct to me. Imagine an urn model with black an white balls in an urn from which balls are drawn without replacement. If the two experiments are independent, you can use either experiment to label the balls in the urn: `m` = number of white balls in the urn, `n` the number of black balls. Then repeat the drawing. What is the probability of drawing `q` or more of the same genes (hence `q-1`, the distribution includes `q` only for `lower.tail = TRUE`) (hence `lower.tail = FALSE`) white balls (significant in exp. A, gene-set size) in `k` draws(number of significant genes in experiment B, gene-set size).

1
brentp23k wrote:

I think that is mostly correct except that you probably want 1 - phyper(...).

Examples

The probability of out of ~20K genes (not accounting for -m). Having 10 shared out of 2 random subsets of 100 should be very small.

``````> 1 - phyper(10, 100, 20000, 100, log.p=F)
 2.582823e-12
``````

The number probability of having only 1 shared should be a bit larger:

``````> 1 - phyper(1, 100, 20000, 100, log.p=F)
 0.08868589
``````

EDIT: you actually need to use:

``````> phyper(9, 100, 20000 - 100, 100, lower.tail=F)
``````
1

Michael, thanks! I missed that. :)

instead of using 1-phyper you could also set lower.tail=F, that's what OP did, thus this is both correct.

Yes, just double checked, both phyper with lower-tail=false and (1-phyper) give same results as Michael mentioned. Thank you all.

Hi Brent, I am bit confused, in the querry q=overlap -1 while in your answer you assume 10 shared out of 2 random subsets. You put 10 as it is and does not make q=9?

who is right here?

1
sjorsvanheuveln50 wrote:

If you want to know what the chance is for exactly q+1 number of overlapping genes, you should subtract the the phyper function like this:

`phyper(q, m, n, k, lower.tail = F) - phyper(q+1, m, n, k, lower.tail = F)`

(with q the number of overlaps -1)

This is because phyper gives the chance for q+1 overlaps OR MORE. So subtracting q+2 will give you the probabability of EXACTLY q+1 overlaps.
I checked it with the following script which prints the probability distribution. The total sum of probabilities is exactly 1 here.

```tot = 0
cat('o','p',sep=' ')
for (hits in 0:100){tot = tot + (phyper(q=hits-1,m=100,n=20000-100,k=100, lower.tail=F)-phyper(q=hits,m=100,n=20000-100,k=100, lower.tail=F))
cat(hits,phyper(q=hits-1,m=100,n=20000-100,k=100, lower.tail=F)-phyper(q=hits,m=100,n=20000-100,k=100, lower.tail=F),'\n',sep=' ')}
tot```

I thought I'd mention this, because while I was reading this I was under the impression that the original answer asked for the chance for an EXACT number of overlaps.