View source: R/recipes-step_box_cox.R
step_box_cox | R Documentation |
step_box_cox
creates a specification of a recipe
step that will transform data using a Box-Cox
transformation. This function differs from
recipes::step_BoxCox
by adding multiple methods
including Guerrero lambda optimization and handling for
negative data used in the Forecast R Package.
step_box_cox(
recipe,
...,
method = c("guerrero", "loglik"),
limits = c(-1, 2),
role = NA,
trained = FALSE,
lambdas_trained = NULL,
skip = FALSE,
id = rand_id("box_cox")
)
## S3 method for class 'step_box_cox'
tidy(x, ...)
recipe |
A |
... |
One or more selector functions to choose which
variables are affected by the step. See |
method |
One of "guerrero" or "loglik" |
limits |
A length 2 numeric vector defining the range to compute the transformation parameter lambda. |
role |
Not used by this step since no new variables are created. |
trained |
A logical to indicate if the quantities for preprocessing have been estimated. |
lambdas_trained |
A numeric vector of transformation values. This
is |
skip |
A logical. Should the step be skipped when the recipe
is baked by |
id |
A character string that is unique to this step to identify it. |
x |
A |
The step_box_cox()
function is designed specifically to handle time series
using methods implemented in the Forecast R Package.
Negative Data
This function can be applied to Negative Data.
Lambda Optimization Methods
This function uses 2 methods for optimizing the lambda selection from the Forecast R Package:
method = "guerrero"
: Guerrero's (1993) method is used, where lambda minimizes
the coefficient of variation for subseries of x.
method = loglik
: the value of lambda is chosen to maximize the profile
log likelihood of a linear model fitted to x. For non-seasonal data, a
linear time trend is fitted while for seasonal data, a linear time trend
with seasonal dummy variables is used.
An updated version of recipe
with the new step
added to the sequence of existing steps (if any). For the
tidy
method, a tibble with columns terms
(the
selectors or variables selected) and value
(the
lambda estimate).
Guerrero, V.M. (1993) Time-series analysis supported by power transformations. Journal of Forecasting, 12, 37–48.
Box, G. E. P. and Cox, D. R. (1964) An analysis of transformations. JRSS B 26 211–246.
Time Series Analysis:
Engineered Features: step_timeseries_signature()
, step_holiday_signature()
, step_fourier()
Diffs & Lags step_diff()
, recipes::step_lag()
Smoothing: step_slidify()
, step_smooth()
Variance Reduction: step_box_cox()
Imputation: step_ts_impute()
, step_ts_clean()
Padding: step_ts_pad()
Transformations to reduce variance:
recipes::step_log()
- Log transformation
recipes::step_sqrt()
- Square-Root Power Transformation
Recipe Setup and Application:
recipes::recipe()
recipes::prep()
recipes::bake()
library(dplyr)
library(recipes)
FANG_wide <- FANG %>%
select(symbol, date, adjusted) %>%
tidyr::pivot_wider(names_from = symbol, values_from = adjusted)
recipe_box_cox <- recipe(~ ., data = FANG_wide) %>%
step_box_cox(FB, AMZN, NFLX, GOOG) %>%
prep()
recipe_box_cox %>% bake(FANG_wide)
recipe_box_cox %>% tidy(1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.