esmtools.stats.linregress

esmtools.stats.linregress(x, y=None, dim='time', nan_policy='none')[source]

Vectorized applciation of scipy.stats.linregress.

Note

This function will try to infer the time freqency of sampling if x is in datetime units. The final slope and standard error will be returned in the original units per that frequency (e.g. SST per year). If the frequency cannot be inferred (e.g. because the sampling is irregular), it will return in the original units per day (e.g. SST per day).

Parameters:
  • x (xarray object) – Independent variable (predictor) for linear regression. If y is None, treat x as the dependent variable and remove slope over dim.
  • y (xarray object, optional) – Dependent variable (predictand) for linear regression. If None, treat x as the predictand.
  • dim (str, optional) – Dimension to apply linear regression over. Defaults to “time”.
  • nan_policy (str, optional) –

    Policy to use when handling nans. Defaults to “none”.

    • ’none’, ‘propagate’: If a NaN exists anywhere on the given dimension,
      return nans for that whole dimension.
    • ’raise’: If a NaN exists at all in the datasets, raise an error.
    • ’omit’, ‘drop’: If a NaN exists in x or y, drop that index and
      compute the slope without it.
Returns:

Slope, intercept, correlation, p value, and standard error for

the linear regression. These 5 parameters are added as a new dimension “parameter”.

Return type:

xarray object