alphapepttools.tl.nan_safe_bh_correction

alphapepttools.tl.nan_safe_bh_correction#

alphapepttools.tl.nan_safe_bh_correction(pvals)#

Apply Benjamini-Hochberg correction with NaN-safe handling.

Scipy.stats.false_discovery_control is not nan-safe, we need to delete nans, apply correction, then re-insert nans. This method preserves nans in their original positions while applying BH correction to valid p-values.

Parameters:

pvals (np.array) – Array of p-values, may contain NaNs.

Return type:

array

Returns:

np.array Array with BH-corrected p-values, NaNs preserved in original positions.

Examples

>>> import numpy as np
>>> from alphapepttools.tl.stats import nan_safe_bh_correction
>>> pvals = np.array([0.01, 0.05, np.nan, 0.001, np.nan])
>>> corrected = nan_safe_bh_correction(pvals)
>>> # Returns [0.015, 0.05, nan, 0.015, nan] (approximately)