Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does SciPy return negative p-values for extremely small p-values with the Fisher-exact test?

I've noticed that the Fisher-exact test in SciPy returns a negative p-value if the p-value is extrememly small:

>>> import scipy as sp
>>> import scipy.stats
>>> x = [[48,60],[3088,17134]]
>>> sp.stats.fisher_exact(x)
(4.4388601036269426, -1.5673906617053035e-11)

In R, using the same 2x2 contingency table:

> a = matrix(c(48,60,3088,17134), nrow=2)
> fisher.test(a)
p-value = 6.409e-13

My question is 1) why does SciPy return a negative p-value? 2) how can I use SciPy to generate the correct p-value?

Thanks for the help.

like image 202
drbunsen Avatar asked Sep 21 '11 17:09

drbunsen


1 Answers

Fisher's exact test uses the hypergeometric distribution.

The version of scipy you are using uses an implementation of the hypergeometric distribution that is not very precise. This is a known problem and has been fixed in the scipy repository.

like image 175
Jeffrey Sax Avatar answered Sep 24 '22 19:09

Jeffrey Sax