22 Statistics: compute Fisher exact
You can use pyranges to compute Fisher Exact quickly. To do so you need to have the package fisher installed.
import pyranges as pr
= pr.random(1000)
gr import numpy as np
= np.random.randint(0, high=20, size=1000)
n1 = np.random.randint(0, high=20, size=1000)
d2 = np.random.randint(0, high=20, size=1000)
n2 = np.random.randint(0, high=20, size=1000)
d1 = pr.stats.fisher_exact(n1, n2, d1, d2).head() fe
## /usr/share/miniconda/lib/python3.9/site-packages/pyranges-0.0.115-py3.9.egg/pyranges/statistics.py:163: RuntimeWarning: divide by zero encountered in true_divide
## /usr/share/miniconda/lib/python3.9/site-packages/pyranges-0.0.115-py3.9.egg/pyranges/statistics.py:163: RuntimeWarning: invalid value encountered in true_divide
print(fe)
## OR P PLeft PRight
## 0 0.972222 1.000000 0.620747 0.652569
## 1 0.333333 0.249881 0.145479 0.965552
## 2 1.909091 0.476752 0.891398 0.311049
## 3 0.333333 0.096384 0.051679 0.986081
## 4 0.836601 1.000000 0.500000 0.724388
You can get the false-discovery rate corrected fdr with pyranges.stats.fdr
:
print(pr.stats.fdr(fe.P))
## 0 1.000000
## 1 0.624702
## 2 0.794587
## 3 0.481922
## 4 1.000000
## Name: P, dtype: float64