library(tidyverse)
library(timetk)
# DATA ----
m750 <- m4_monthly %>% filter(id == "M750")
# Get the most recent 3 years as testing, and previous 10 years as training
m750 %>%
time_series_split(initial = "10 years", assess = "3 years")
# Skip the most recent 3 years
m750 %>%
time_series_split(
initial = "10 years",
assess = "3 years",
skip = "3 years",
slice = 2 # <- Returns 2nd slice, 3-years back
)
# Add 1 year lag for testing overlap
m750 %>%
time_series_split(
initial = "10 years",
assess = "3 years",
skip = "3 years",
slice = 2,
lag = "1 year" # <- Overlaps training/testing by 1 year
)
Run the code above in your browser using DataLab