xskillscore.spearman_r

xskillscore.spearman_r(a, b, dim=None, weights=None, skipna=False, keep_attrs=False)

Spearman’s correlation coefficient.

Parameters
  • a (xarray.Dataset or xarray.DataArray) – Labeled array(s) over which to apply the function.

  • b (xarray.Dataset or xarray.DataArray) – Labeled array(s) over which to apply the function.

  • dim (str, list) – The dimension(s) to apply the correlation along. Note that this dimension will be reduced as a result. Defaults to None reducing all dimensions.

  • weights (xarray.Dataset or xarray.DataArray or None) – Weights matching dimensions of dim to apply during the function.

  • skipna (bool) – If True, skip NaNs when computing function.

  • keep_attrs (bool) – If True, the attributes (attrs) will be copied from the first input to the new one. If False (default), the new object will be returned without attributes.

Returns

Spearman’s correlation coefficient.

Return type

xarray.DataArray or xarray.Dataset

See also

scipy.stats.spearman_r()

References

https://github.com/scipy/scipy/blob/v1.3.1/scipy/stats/stats.py#L3613-L3764 https://en.wikipedia.org/wiki/Spearman%27s_rank_correlation_coefficient

Examples

>>> import numpy as np
>>> import xarray as xr
>>> from xskillscore import spearman_r
>>> a = xr.DataArray(np.random.rand(5, 3, 3),
                    dims=['time', 'x', 'y'])
>>> b = xr.DataArray(np.random.rand(5, 3, 3),
                    dims=['time', 'x', 'y'])
>>> spearman_r(a, b, dim='time')