lib5c.util.statistics module¶
Module containing utility functions related to statistical transformation, correction, or combination of p-values.
-
lib5c.util.statistics.
adjust_pvalues
(pvalue_matrix, method='fdr_bh')[source]¶ Performs multiple testing correction on a matrix of p-values.
Parameters: - pvalue_matrix (np.ndarray) – The matrix of p-values, representing many tests that were performed.
- method (str) –
Method used for testing and adjustment of pvalues. Can be either the full name or initial letters. Available methods are
`bonferroni` : one-step correction `sidak` : one-step correction `holm-sidak` : step down method using Sidak adjustments `holm` : step-down method using Bonferroni adjustments `simes-hochberg` : step-up method (independent) `hommel` : closed method based on Simes tests (non-negative) `fdr_bh` : Benjamini/Hochberg (non-negative) `fdr_by` : Benjamini/Yekutieli (negative) `fdr_tsbh` : two stage fdr correction (non-negative) `fdr_tsbky` : two stage fdr correction (non-negative)
Returns: The matrix of adjusted p-values. Same size and shape as pvalue_matrix.
Return type: np.ndarray
-
lib5c.util.statistics.
convert_to_two_tail
(pvalue)[source]¶ Converts a one-tail p-value to a two-tail p-value.
Only valid for continuous distributions (otherwise I think the PMF evaluation at the obs value needs to be taken into account when reversing the test).
Array-safe, nan-safe, position-independent.
Parameters: pvalue (float) – The one-tail p-values to be folded into two-tail pvalues. Returns: The two-tail p-values. Return type: float
-
lib5c.util.statistics.
stouffer
(pvalue_matrix, axis=None)[source]¶ Combines a matrix of p-values along a specified axis using Stouffer’s Z-transform.
Parameters: - pvalue_matrix (np.ndarray) – Matrix of p-values.
- axis (int, optional) – The axis to combine p-values along. Pass None to combine all of them.
Returns: Array of combined p-values.
Return type: np.ndarray
Notes
Element-by-element, this should be equivalent to:
scipy.stats.combine_pvalues(pvalue_matrix, method='stouffer')[1]
except that this function is vectorized.
Examples
>>> from scipy.stats import combine_pvalues >>> stouffer([0.1, 0.1]) == combine_pvalues([0.1, 0.1], ... method='stouffer')[1] True >>> stouffer(np.array([[0.1, 0.1], ... [0.2, 0.2]]), axis=1) array([0.03496316, 0.11697758])