mesmer.stats.yeo_johnson_transform

mesmer.stats.yeo_johnson_transform#

mesmer.stats.yeo_johnson_transform(yearly_pred, monthly_residuals, lambda_coeffs)#

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

Parameters:
  • yearly_pred (xr.DataArray of shape (n_years, n_gridcells)) – yearly values used as predictors for the lambdas.

  • monthly_residuals (xr.DataArray of shape (n_years*12, n_gridcells)) – Monthly residuals after removing harmonic model fits, used to fit for the optimal transformation parameters (lambdas).

  • lambda_coeffs (xr.DataArray) – The parameters of the power transformation of shape (months, coeff, n_gridcells) for each gridcell, calculated using lambda_function.

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.