diff --git a/xskillscore/core/stattests.py b/xskillscore/core/stattests.py index ef1238c4..5dbcc820 100644 --- a/xskillscore/core/stattests.py +++ b/xskillscore/core/stattests.py @@ -1,14 +1,26 @@ from __future__ import annotations -import warnings from typing import Literal, Mapping, Optional, Tuple, Union +import numpy as np import xarray as xr from statsmodels.stats.multitest import multipletests as statsmodels_multipletests from .types import XArray +def _multipletests_numpy(pvals, **kwargs): + """Call statsmodels multipletests and broadcast scalar outputs to match pvals shape.""" + reject, pvals_corrected, alphacSidak, alphacBonf = statsmodels_multipletests(pvals, **kwargs) + n = len(pvals) + return ( + reject.astype(float), + pvals_corrected, + np.full(n, float(alphacSidak)), + np.full(n, float(alphacBonf)), + ) + + def multipletests( p: XArray, alpha: float = 0.05, @@ -99,6 +111,7 @@ def multipletests( Examples -------- + >>> np.random.seed(42) >>> p = xr.DataArray( ... np.random.normal(size=(3, 3)), ... coords=[("x", np.arange(3)), ("y", np.arange(3))], @@ -110,17 +123,17 @@ def multipletests( [ 0. , 1. , 1. ], [ 0. , 0. , 1. ]], - [[ 0.49671415, -0.1382643 , 0.64768854], - [ 1. , -0.23415337, -0.23413696], - [ 1. , 0.76743473, -0.46947439]], + [[ 0.89408548, -0.31109468, 0.97153281], + [ 1. , -1.05369019, -0.70241087], + [ 1. , 0.98670179, -4.22526947]], - [[ 0.1 , 0.1 , 0.1 ], - [ 0.1 , 0.1 , 0.1 ], - [ 0.1 , 0.1 , 0.1 ]], + [[ 0.01163847, 0.01163847, 0.01163847], + [ 0.01163847, 0.01163847, 0.01163847], + [ 0.01163847, 0.01163847, 0.01163847]], - [[ 0.1 , 0.1 , 0.1 ], - [ 0.1 , 0.1 , 0.1 ], - [ 0.1 , 0.1 , 0.1 ]]]) + [[ 0.01111111, 0.01111111, 0.01111111], + [ 0.01111111, 0.01111111, 0.01111111], + [ 0.01111111, 0.01111111, 0.01111111]]]) Coordinates: * result (result) reject.sum()