Skip to content

statspai.mht

mht

Multiple Hypothesis Testing (MHT) module for StatsPAI.

Provides corrections for simultaneous inference across many outcomes or subgroups --- the single most common gap when Python users replicate empirical economics workflows that rely on Stata's rwolf or wyoung.

Estimators and utilities:

  • Romano-Wolf stepdown (Romano & Wolf 2005, 2016) --- bootstrap FWER control that exploits dependence across test statistics.
  • Westfall-Young maxT (Westfall & Young 1993) --- single-step resampling-based FWER control.
  • Bonferroni, Holm (1979), Benjamini-Hochberg (1995) --- classical non-resampling adjustments included for comparison.
  • adjust_pvalues() --- convenience dispatcher across all methods.

RomanoWolfResult dataclass

Container for Romano-Wolf multiple hypothesis testing results.

Attributes:

Name Type Description
table DataFrame

One row per outcome with columns: outcome, coef, se, t, p_value, p_rw, p_bonf, p_holm, p_bh.

n_outcomes int
n_boot int
n_obs int

summary

summary() -> str

Pretty-print the results table.

plot

plot(figsize: tuple = (8, 5))

Dot-plot comparing unadjusted and adjusted p-values.

Returns:

Type Description
fig, ax : matplotlib Figure and Axes

adjust_pvalues

adjust_pvalues(pvalues: Sequence[float], method: str = 'holm') -> ndarray

Adjust p-values for multiple comparisons.

Parameters:

Name Type Description Default
pvalues array - like

Unadjusted p-values.

required
method str

Adjustment method. One of:

  • 'bonferroni' -- Bonferroni correction.
  • 'holm' -- Holm (1979) step-down.
  • 'bh' or 'fdr' -- Benjamini-Hochberg FDR.

For Romano-Wolf or Westfall-Young adjustments (which require the original data and bootstrap), use :func:romano_wolf directly.

``'holm'``

Returns:

Type Description
ndarray

Adjusted p-values.

Examples:

>>> import statspai as sp
>>> sp.adjust_pvalues([0.01, 0.04, 0.03, 0.20], method='holm')
array([0.04, 0.12, 0.09, 0.20])

bonferroni

bonferroni(pvalues: Sequence[float]) -> ndarray

Bonferroni correction: p_adj = min(p * S, 1).

Parameters:

Name Type Description Default
pvalues array - like

Unadjusted p-values.

required

Returns:

Type Description
ndarray

Bonferroni-adjusted p-values.

holm

holm(pvalues: Sequence[float]) -> ndarray

Holm (1979) step-down correction.

Sort p-values ascending; for rank i (1-based): p_adj(i) = max(p_adj(i-1), min(p(i) * (S - i + 1), 1)).

Parameters:

Name Type Description Default
pvalues array - like

Unadjusted p-values.

required

Returns:

Type Description
ndarray

Holm-adjusted p-values (in original order).

benjamini_hochberg

benjamini_hochberg(pvalues: Sequence[float]) -> ndarray

Benjamini-Hochberg (1995) FDR correction.

Sort p-values ascending; for rank i (1-based): p_adj(i) = min(p(i) * S / i, 1), with reverse-cumulative-min to enforce monotonicity.

Parameters:

Name Type Description Default
pvalues array - like

Unadjusted p-values.

required

Returns:

Type Description
ndarray

BH-adjusted p-values (in original order).