Skip to content

fdr_adjust

fdr_adjust

fdr_adjust(pvalues, *, method: str = 'bh') -> ndarray

Multiple-testing correction of a vector of p-values (Benjamini-Hochberg).

LISA and per-station tests run one hypothesis per station; at thousands of stations the uncorrected count of "significant" hot/cold spots is dominated by false positives. This returns FDR-adjusted p-values (NaNs preserved), so a study can threshold on a controlled false-discovery rate instead of a raw per-test alpha.

Parameters:

Name Type Description Default
pvalues array - like

Raw p-values (may contain NaN for untested units).

required
method ('bh', 'by')

Benjamini-Hochberg (independent/positively-dependent) or Benjamini-Yekutieli (arbitrary dependence).

"bh"
References

Benjamini, Y. & Hochberg, Y. (1995). Controlling the false discovery rate. JRSS B, 57(1), 289-300.

See Also

local_morans_i : The per-station tests this corrects.

Examples:

>>> [round(float(p), 2) for p in fdr_adjust([0.01, 0.04, 0.5])]
[0.03, 0.06, 0.5]
Source code in src/gbfs_toolkit/spatial/analytics.py
def fdr_adjust(pvalues, *, method: str = "bh") -> np.ndarray:
    """Multiple-testing correction of a vector of p-values (Benjamini-Hochberg).

    LISA and per-station tests run one hypothesis per station; at thousands of
    stations the uncorrected count of "significant" hot/cold spots is dominated by
    false positives. This returns FDR-adjusted p-values (NaNs preserved), so a
    study can threshold on a controlled false-discovery rate instead of a raw
    per-test alpha.

    Parameters
    ----------
    pvalues : array-like
        Raw p-values (may contain NaN for untested units).
    method : {"bh", "by"}, default "bh"
        Benjamini-Hochberg (independent/positively-dependent) or
        Benjamini-Yekutieli (arbitrary dependence).

    References
    ----------
    Benjamini, Y. & Hochberg, Y. (1995). Controlling the false discovery rate.
    *JRSS B*, 57(1), 289-300.

    See Also
    --------
    [`local_morans_i`][gbfs_toolkit.local_morans_i] : The per-station tests this corrects.

    Examples
    --------
    >>> [round(float(p), 2) for p in fdr_adjust([0.01, 0.04, 0.5])]
    [0.03, 0.06, 0.5]
    """
    from scipy.stats import false_discovery_control

    p = np.asarray(pvalues, dtype="float64")
    out = np.full(p.shape, np.nan)
    finite = np.isfinite(p)
    if finite.any():
        out[finite] = false_discovery_control(p[finite], method=method)
    return out