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

Returns the linear slope with y regressed onto x.


This function will try to infer the time freqency of sampling if x is in datetime units. The final slope 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).

  • 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.

Slopes computed through a least-squares linear regression.

Return type:

xarray object