step_lag_difference: Calculate a lagged difference

View source: R/step_lag_difference.R

step_lag_differenceR Documentation

Calculate a lagged difference

Description

step_lag_difference() creates a specification of a recipe step that will generate one or more new columns of derived data.

Usage

step_lag_difference(
  recipe,
  ...,
  role = "predictor",
  horizon = 7,
  prefix = "lag_diff_",
  skip = FALSE,
  id = rand_id("lag_diff")
)

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 variables for this step. See recipes::selections() for more details.

role

For model terms created by this step, what analysis role should they be assigned? lag is default a predictor while ahead is an outcome.

horizon

Scalar or vector. Time period(s) over which to calculate differences.

prefix

A character string that will be prefixed to the new column.

skip

A logical. Should the step be skipped when the recipe is baked by bake()? While all operations are baked when prep() is run, some operations may not be able to be conducted on new data (e.g. processing the outcome variable(s)). Care should be taken when using skip = TRUE as it may affect the computations for subsequent operations.

id

A unique identifier for the step

Value

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

See Also

Other row operation steps: step_adjust_latency(), step_epi_lag(), step_growth_rate()

Examples

r <- epi_recipe(covid_case_death_rates) %>%
  step_lag_difference(case_rate, death_rate, horizon = c(7, 14)) %>%
  step_epi_naomit()
r

r %>%
  prep(covid_case_death_rates) %>%
  bake(new_data = NULL)

cmu-delphi/epipredict documentation built on March 5, 2025, 12:17 p.m.