mesmer.stats.YeoJohnsonTransformer.transform

mesmer.stats.YeoJohnsonTransformer.transform#

YeoJohnsonTransformer.transform(yearly_pred, monthly_residuals, lambda_coeffs, time_dim='time')#

transform monthly_residuals following Yeo-Johnson transformer with parameters \(\lambda\), fit with fit_yeo_johnson_transform.

Parameters:
  • yearly_pred (xr.DataArray) – yearly values used as predictors for the lambdas, must contain time_dim but can have additional dimensions for example gridcells or members.

  • monthly_residuals (xr.DataArray) – Monthly residuals after removing harmonic model fits, used to fit for the optimal transformation parameters (lambdas). Has time_dim which is of length len(yearly_pred[time_dim]) * 12 and can also contain the same additional dimensions as yearly_pred.

  • lambda_coeffs (xr.DataArray) – DataArray containing the estimated coefficients needed to compute lambda with dimensions “month”, “coeff” and additional dims on inputs. Calculated using lambda_function.

  • time_dim (str, default: “time”) – Name of the time dimension in the input data used to align monthly residuals and yearly predictor data (needs to be the same in both).

Returns:

xr.Dataset – Dataset containing the transformed monthly residuals and the parameters of the power transformation for each gridcell.

Notes

The Yeo-Johnson transformation is given by:

if \(X \leq 0\) and \(\lambda = 0\):

\(X_{trans} = log(X + 1)\)

elif \(X \leq 0\) and \(\lambda \neq 0\):

\(X_{trans} = \frac{(X + 1)^{\lambda} - 1}{\lambda}\)

elif \(X < 0\) and \(\lambda \neq 2\):

\(X_{trans} = - \frac{(-X + 1)^{2 - \lambda} - 1}{2 - \lambda}\)

elif \(X < 0\) and \(\lambda = 2\):

\(X_{trans} = - log(-X + 1)\)

Note that \(X\) and \(X_{trans}\) have the same sign. Also see sklearn’s PowerTransformer.