Solved – One tailed Fisher’s exact test and the hypergeometric distribution

fishers-exact-testhypergeometric-distribution

I'm working on a software and need to do some statistics. In my case I'm comparing two different networks that have a certain number of nodes with attributes and want to test with a Fisher's exact test if some of these attributes are enriched in the smaller one.
I also have a good math library that is able to calculate hypergeometric distributions and want to use it.

So after reading a bit it seemed to me that you need to calculate the probabilities for your obtained data and more extreme cases and then add these.

If this is correct and my table looks e.g. like

-------------------------------------
|                 |Network1|Network2|
-------------------------------------
|has Attribute    |a=7     |b=10    |
-------------------------------------
|has not Attribute|c=17794 |d=1107  |
-------------------------------------

How more extreme tables do I have to calculate for a one-tailed test? I guess until a=0, b=17, c=17801 and d=1100?

Thanks a lot!

Best Answer

You are right that there are 7 more extreme tables, as listed below including the original one. The p-value for one-tailed Fisher's exact test is the sum of all the hypergeometric probabilities.

Depending the odds ratio (a*d)/(b*c), if a*d <= b*c, you should use "less" alternative hypothesis, otherwise the "greater" one. Fisher's exact test assumes that marginal totals are fixed, so the whole table can be determined by one cell. If a*d <= b*c, the number of more extreme tables is n=min(a,d) (in your example, n=a, a can range within 0, 1, ..., 6 in more extreme tables), otherwise n=min(b,c).

-------------------  -------------------  -------------------  -------------------
|a=7     |b=10    |  |a=6     |b=11    |  |a=5     |b=12    |  |a=4     |b=13    |
-------------------  -------------------  -------------------  -------------------
|c=17794 |d=1107  |  |c=17795 |d=1106  |  |c=17796 |d=1105  |  |c=17797 |d=1104  |
-------------------  -------------------  -------------------  -------------------
-------------------  -------------------  -------------------  -------------------
|a=3     |b=14    |  |a=2     |b=15    |  |a=1     |b=16    |  |a=0     |b=17    |
-------------------  -------------------  -------------------  -------------------
|c=17798 |d=1103  |  |c=17799 |d=1102  |  |c=17800 |d=1101  |  |c=17801 |d=1100  |
-------------------  -------------------  -------------------  -------------------