step_epi_lag | R Documentation |
step_epi_lag
and step_epi_ahead
create a specification of a recipe step
that will add new columns of shifted data. The former will created a lag
column, while the latter will create a lead column. Shifted data will
by default include NA values where the shift was induced.
These can be properly removed with step_epi_naomit()
, or you may
specify an alternative filler value with the default
argument.
step_epi_lag(
recipe,
...,
lag,
role = "predictor",
prefix = "lag_",
default = NA,
skip = FALSE,
id = rand_id("epi_lag")
)
step_epi_ahead(
recipe,
...,
ahead,
role = "outcome",
prefix = "ahead_",
default = NA,
skip = FALSE,
id = rand_id("epi_ahead")
)
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 |
lag , ahead |
A vector of integers. Each specified column will be the lag or lead for each value in the vector. Lag integers must be nonnegative, while ahead integers must be positive. |
role |
For model terms created by this step, what analysis role should
they be assigned? |
prefix |
A character string that will be prefixed to the new column. |
default |
Determines what fills empty rows left by leading/lagging (defaults to NA). |
skip |
A logical. Should the step be skipped when the
recipe is baked by |
id |
A unique identifier for the step |
The step assumes that the data are already in the proper sequential order for shifting.
The prefix
and id
arguments are unchangeable to ensure that the code runs
properly and to avoid inconsistency with naming. For step_epi_ahead
, they
are always set to "ahead_"
and "epi_ahead"
respectively, while for
step_epi_lag
, they are set to "lag_"
and "epi_lag
, respectively.
An updated version of recipe
with the new step added to the
sequence of any existing operations.
Other row operation steps:
step_adjust_latency()
,
step_growth_rate()
,
step_lag_difference()
Other row operation steps:
step_adjust_latency()
,
step_growth_rate()
,
step_lag_difference()
r <- epi_recipe(covid_case_death_rates) %>%
step_epi_ahead(death_rate, ahead = 7) %>%
step_epi_lag(death_rate, lag = c(0, 7, 14))
r
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.