模块:
statgpu.inference
最后更新: 2026-06-14
后端: NumPy, CuPy, PyTorch
当同时检验多个假设时,至少出现一次错误发现的概率会增加。 本模块提供 P 值校正和合并方法,用于控制族错误率(FWER)或错误发现率(FDR)。
给定
Bonferroni correction (FWER 控制):
Holm step-down procedure (FWER control, uniformly more powerful than Bonferroni):
- Order p-values:
$p_{(1)} \leq p_{(2)} \leq \ldots \leq p_{(m)}$ - Reject
$H_{(i)}$ if$p_{(i)} < \alpha / (m - i + 1)$ - Adjusted: $\tilde{p}{(i)} = \max{j \leq i} \min((m-j+1) \cdot p_{(j)}, 1)$
Benjamini-Hochberg (BH) (FDR 控制):
- Order p-values:
$p_{(1)} \leq p_{(2)} \leq \ldots \leq p_{(m)}$ - Find largest
$k$ such that$p_{(k)} \leq \frac{k}{m} \alpha$ - Reject
$H_{(1)}, \ldots, H_{(k)}$ - Adjusted: $\tilde{p}{(i)} = \min{j \geq i} \min(\frac{m}{j} p_{(j)}, 1)$
Benjamini-Yekutieli (BY) (FDR control under arbitrary dependence):
- Same as BH but with correction factor
$\sum_{j=1}^{m} \frac{1}{j}$ - More conservative than BH but valid under any dependence structure
Hochberg step-up procedure (FWER control, assumes non-negative correlation):
- Start from largest p-value
- Accept
$H_{(i)}$ if$p_{(i)} > \alpha / (m - i + 1)$ - Adjusted: $\tilde{p}{(i)} = \min{j \geq i} \min((m-j+1) \cdot p_{(j)}, 1)$
Fisher's method (chi-squared combination):
- 在
$H_0$ :$T \sim \chi^2_{2m}$ - Powerful when a small subset of p-values is very small
Cauchy Combination Test (ACAT) (robust to arbitrary dependence):
- Approximately distributed as Cauchy under
$H_0$ - No assumption on dependence structure
- Liu & Xie (2020)
Stouffer's method (z 分数合并):
- 在
$H_0$ :$T \sim N(0, 1)$ - Most powerful when effects are in the same direction
| Parameter | Type | Default | Description |
|---|---|---|---|
pvalues |
array-like | — | Raw p-values |
method |
str | 'bh' |
'bh', 'by', 'holm', 'bonferroni', 'hochberg' |
alpha |
float | 0.05 |
Significance level |
axis |
int or None | None |
Axis for batch processing |
backend |
str | 'auto' |
'numpy', 'cupy', 'torch', 'auto' |
| Parameter | Type | Default | Description |
|---|---|---|---|
pvalues |
array-like | — | Raw p-values |
method |
str | 'fisher' |
'fisher', 'cauchy'/'acat', 'stouffer' |
weights |
array-like | None |
Non-negative weights (cauchy/stouffer) |
axis |
int or None | None |
Axis for batch processing |
backend |
str | 'auto' |
'numpy', 'cupy', 'torch', 'auto' |
import numpy as np
from statgpu.inference import adjust_pvalues, combine_pvalues
# Raw p-values from 5 hypothesis tests
pvals = np.array([0.001, 0.01, 0.03, 0.05, 0.50])
# Benjamini-Hochberg FDR control
reject, pvals_adj = adjust_pvalues(pvals, method='bh', alpha=0.05)
print(f"Rejected: {reject}")
print(f"Adjusted p-values: {pvals_adj}")
# Fisher combination
stat, p_global = combine_pvalues(pvals, method='fisher')
print(f"Fisher statistic: {stat:.4f}, global p-value: {p_global:.6f}")
# Cauchy combination (robust to dependence)
stat, p_global = combine_pvalues(pvals, method='cauchy')
# Stouffer with weights
weights = np.array([1.0, 1.0, 1.0, 0.5, 0.5])
stat, p_global = combine_pvalues(pvals, method='stouffer', weights=weights)GPU acceleration:
import torch
from statgpu.inference import adjust_pvalues, combine_pvalues
pvals_gpu = torch.tensor([0.001, 0.01, 0.03, 0.05, 0.50], device='cuda')
reject, pvals_adj = adjust_pvalues(pvals_gpu, method='bh', backend='torch')| Method | Returns | Description |
|---|---|---|
adjust_pvalues |
(reject, pvals_adj) |
Boolean rejection array + adjusted p-values |
combine_pvalues |
(statistic, p_global) |
Test statistic + global p-value |
Q: 应该用哪种方法?
A: FDR 控制用 BH(最常用)。严格 FWER 控制用 Bonferroni/Holm。P 值相关时用 Cauchy。
Q: 可以用于全基因组关联分析吗?
A: 可以。BH 是 GWAS 的标准方法。对于相关检验,使用 Cauchy 合并。
Q: What's the difference between FDR and FWER?
A: FDR = 错误拒绝的期望比例。FWER = 至少一次错误拒绝的概率。FDR 更宽松。
- R:
p.adjust()for adjustment,pchisq()for Fisher - statsmodels:
multipletests()(BH, Holm, Bonferroni, BY, Hochberg) - scipy:
combine_pvalues()(Fisher, Stouffer, Tippett)
- Benjamini, Y. & Hochberg, Y. (1995). "Controlling the False Discovery Rate: A Practical and Powerful Approach to Multiple Testing." Journal of the Royal Statistical Society: Series B, 57(1), 289-300.
- Benjamini, Y. & Yekutieli, D. (2001). "The Control of the False Discovery Rate in Multiple Testing under Dependency." Annals of Statistics, 29(4), 1165-1188.
- Holm, S. (1979). "A Simple Sequentially Rejective Multiple Test Procedure." Scandinavian Journal of Statistics, 6(2), 65-70.
- Fisher, R.A. (1925). Statistical Methods for Research Workers. Oliver and Boyd.
- Liu, Y. & Xie, J. (2020). "Cauchy Combination Test: A Powerful Test With Analytic p-Value Calculation 在 Arbitrary Dependency Structures." Journal of the American Statistical Association, 115(529), 393-402.
- Stouffer, S.A. et al. (1949). The American Soldier. Princeton University Press.