knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

The oilPrep package is inspired by the recipe package which does a series of data pre-processing for the oil data set in the gamlss package.

Load the package and oil data set.

# install oilPrep if you haven't
# devtools::install_github("mohowu/oilPrep", build_vignettes = TRUE)

library(oilPrep)
library(gamlss)
data(oil)

First we create a rec object where we specify what data and response variable to use.

rec0 <- rec(oil, "OILPRICE")

The rec0 object contains:

head(rec0$data)
rec0$meta

No meta information yet as no transformations have been done.

rec0$y

Then we can specify the data transformation we want by using the step_* functions.

rec1 <- rec0 %>% 
  step_roll("CL2_log", "CL2_log_roll_mean_5", "mean", 5) %>% 
  step_roll("CL2_log", "CL2_log_roll_sd_5", "sd", 5) %>% 
  step_shift("CL2_log", "CL2_log_lag_2", "lag", 2) %>% 
  step_shift("CL2_log", "CL2_log_lead_2", "lead", 2) %>% 
  step_diff("CL2_log", "CL2_log_diff") %>%
  step_two(c("CL2_log", "CL3_log"), "CL2_3_log_spread", "spread") %>% 
  step_two(c("CL2_log", "CL3_log"), "CL2_3_log_ratio", "ratio") %>% 
  step_two(c("CL2_log", "CL3_log"), "CL2_3_log_prod", "product") 

To get the transformed data.

head(rec1$data, 10)

To get the meta data.

rec1$meta


MohoWu/oilPrep documentation built on Dec. 17, 2021, 4:20 a.m.