step_robust_boxcox: Robust Box-Cox Transformation Recipe Step

View source: R/recipe_steps_robust.R

step_robust_boxcoxR Documentation

Robust Box-Cox Transformation Recipe Step

Description

step_robust_boxcox() creates a specification of a recipe step that transforms the selected variables toward central normality with the robust Box-Cox transformation of robust_boxcox(). It is the robust counterpart of recipes::step_BoxCox().

Usage

step_robust_boxcox(
  recipe,
  ...,
  role = NA,
  trained = FALSE,
  quantile = 0.99,
  nbsteps = 2,
  standardize = TRUE,
  res = NULL,
  columns = NULL,
  skip = FALSE,
  id = recipes::rand_id("robust_boxcox")
)

Arguments

recipe

A recipe object. The step will be added to the sequence of operations for this recipe.

...

One or more selector functions to choose the predictors (for example, the spectral channels). See recipes::selections().

role

Not used by this step, since no new variables are created.

trained

A logical indicating whether the step has been trained.

quantile

The quantile of the absolute value of a standard normal variable beyond which the standardized transformed values are given weight zero in the re-weighting steps, strictly between 0 and 1. Default is 0.99.

nbsteps

The number of re-weighting steps, a positive integer. Default is 2.

standardize

A logical value: standardize the transformed variables by the mean and standard deviation of the inliers (TRUE, default).

res

The fitted transformation, stored once the step has been trained.

columns

The names of the selected columns, stored once the step has been trained.

skip

A logical. Should the step be skipped when the recipe is baked by recipes::bake()? Keep the default FALSE, so that new data are corrected with the same filter as the training data.

id

A character string that is unique to this step.

Details

The transformation parameter \lambda of each variable is estimated on the training data (Raymaekers and Rousseeuw, 2021), as in robust_boxcox(), and applied unchanged to new data. With standardize = TRUE, the transformed variables are also centered and scaled with the mean and standard deviation of the training inliers. Variables that cannot be transformed (constant ones and, with a warning, those with zero or negative values) are left unchanged. Missing values are ignored by the fit and stay missing; new values that are zero or negative become NA.

tidy() returns a tibble with columns terms, lambda (NA for the variables left unchanged) and id.

Value

An updated version of recipe with the new step added to the sequence of existing steps.

Author(s)

Christian L. Goueguel

See Also

robust_boxcox(), step_robust_yeojohnson() for variables with zero or negative values.

Examples


library(recipes)
data(forageLIBS)
contents <- forageLIBS[c("Ca", "K", "P", "Mn")]
rec <- recipe(~ ., data = contents[1:300, ]) |>
  step_robust_boxcox(all_numeric_predictors())
prepped <- prep(rec)
tidy(prepped, number = 1)
bake(prepped, new_data = contents[301:368, ])


specProc documentation built on Nov. 20, 2026, 5:11 p.m.