step_ts_pad: Pad: Add rows to fill gaps and go from low to high frequency

Description Usage Arguments Details Value See Also Examples

View source: R/recipes-step_ts_pad.R

Description

step_ts_pad creates a a specification of a recipe step that will analyze a Date or Date-time column adding rows at a specified interval.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
step_ts_pad(
  recipe,
  ...,
  by = "day",
  pad_value = NA,
  role = "predictor",
  trained = FALSE,
  columns = NULL,
  skip = FALSE,
  id = rand_id("ts_padding")
)

## S3 method for class 'step_ts_pad'
tidy(x, ...)

Arguments

recipe

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

...

A single column with class Date or POSIXct. See recipes::selections() for more details. For the tidy method, these are not currently used.

by

Either "auto", a time-based frequency like "year", "month", "day", "hour", etc, or a time expression like "5 min", or "7 days". See Details.

pad_value

Fills in padded values. Default is NA.

role

For model terms created by this step, what analysis role should they be assigned?. By default, the function assumes that the new variable columns created by the original variables will be used as predictors in a model.

trained

A logical to indicate if the quantities for preprocessing have been estimated.

columns

A character string of variables that will be used as inputs. This field is a placeholder and will be populated once recipes::prep() is used.

skip

A logical. Should the step be skipped when the recipe is baked by bake.recipe()? While all operations are baked when prep.recipe() 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 character string that is unique to this step to identify it.

x

A step_ts_pad object.

Details

Date Variable

Interval Specification (by)

Padding can be applied in the following ways:

Imputing Missing Values

The generic pad_value defaults to NA, which typically requires imputation. Some common strategies include:

Value

For step_ts_pad, 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), value (the feature names).

See Also

Padding & Imputation:

Time Series Analysis:

Main Recipe Functions:

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
library(recipes)
library(tidyverse)
library(tidyquant)
library(timetk)

FB_tbl <- FANG %>%
    filter(symbol == "FB") %>%
    select(symbol, date, adjusted)


rec_obj <- recipe(adjusted ~ ., data = FB_tbl) %>%
    step_ts_pad(date, by = "day", pad_value = NA)

# View the recipe object
rec_obj

# Prepare the recipe object
prep(rec_obj)

# Bake the recipe object - Adds the padding
bake(prep(rec_obj), FB_tbl)

# Tidy shows which features have been added during the 1st step
#  in this case, step 1 is the step_timeseries_signature step
tidy(prep(rec_obj))
tidy(prep(rec_obj), number = 1)

timetk documentation built on Jan. 19, 2021, 1:06 a.m.