在 Python 中计算调整后的 p 值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25185205/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 19:50:41  来源:igfitidea点击:

Calculating adjusted p-values in Python

pythonstatisticsp-valueq-value

提问by erikfas

So, I've been spending some time looking for a way to get adjusted p-values (aka corrected p-values, q-values, FDR) in Python, but I haven't really found anything. There's the Rfunction p.adjust, but I would like to stick to Python coding, if possible. Is there anything similar for Python?

所以,我一直在寻找一种方法来在 Python 中获得调整后的 p 值(又名校正的 p 值、q 值、FDR),但我还没有真正找到任何东西。有R函数p.adjust,但如果可能的话,我想坚持使用 Python 编码。Python有没有类似的东西?

If this is somehow a bad question, sorry in advance! I did search for answers first, but found none (except a Matlab version)... Any help is appreciated!

如果这是一个不好的问题,请提前抱歉!我确实首先搜索了答案,但没有找到(除了 Matlab 版本)......感谢任何帮助!

回答by JulienD

You can try the module rpy2that allows you to import R functions (b.t.w., a basic search returns How to implement R's p.adjust in Python).

您可以尝试rpy2允许您导入 R 函数的模块(顺便说一句,基本搜索返回How to implement R's p.adjust in Python)。

Another possibility is to look at the maths an redo it yourself, because it is still relatively easy.

另一种可能性是查看数学并自己重做,因为它仍然相对容易。

Apparently there is an ongoing implementation in scipy: http://statsmodels.sourceforge.net/ipdirective/_modules/scikits/statsmodels/sandbox/stats/multicomp.html. Maybe it is already usable.

显然有一个正在进行的实施scipyhttp: //statsmodels.sourceforge.net/ipdirective/_modules/scikits/statsmodels/sandbox/stats/multicomp.html。也许它已经可以使用了。

回答by The Unfun Cat

According to the biostathandbook, the BH is easy to compute.

根据biostathandbook,BH 很容易计算。

def fdr(p_vals):

    from scipy.stats import rankdata
    ranked_p_values = rankdata(p_vals)
    fdr = p_vals * len(p_vals) / ranked_p_values
    fdr[fdr > 1] = 1

    return fdr