I have a list of p-values and I would like to calculate the adjust p-values for multiple comparisons for the FDR. In R, I can use:
pval <- read.csv(\"my_f
Old question, but here's a translation of the R FDR code in python (which is probably fairly inefficient):
def FDR(x):
"""
Assumes a list or numpy array x which contains p-values for multiple tests
Copied from p.adjust function from R
"""
o = [i[0] for i in sorted(enumerate(x), key=lambda v:v[1],reverse=True)]
ro = [i[0] for i in sorted(enumerate(o), key=lambda v:v[1])]
q = sum([1.0/i for i in xrange(1,len(x)+1)])
l = [q*len(x)/i*x[j] for i,j in zip(reversed(xrange(1,len(x)+1)),o)]
l = [l[k] if l[k] < 1.0 else 1.0 for k in ro]
return l