Description Usage Arguments Value Examples
View source: R/HELPER_split_ts_object.R
split_ts_object
is a function to split a time series object into two
parts based on a specified split date. The two parts can then be used
separately, e.g. one part for training a time series model and the other part
for validation of the model.
1 2 3 4 5 6 | split_ts_object(
ts_object,
ts_split_date,
output = c("both", "train", "valid"),
max_length = Inf
)
|
ts_object |
A time series object to be split into two. |
ts_split_date |
A date object or period value (in yyyymm numeric format) indicating the date at which to split the time series object into two. |
output |
What kind of output is wanted from the split, either 'train' (which is the time range before and on the split date), 'valid' (which is the time range after the split date) or 'both'. |
max_length |
A positive integer value indicating the maximum length the resulting ts object should be. This is in case the ts object requires trimming, e.g. to limit the historic data used for training. |
Depending on the value for the 'output' parameter:
'train' - ts object containing the time range before and on the split date
'valid' - ts object containing the time range after the split date
'both' - named list containing both of the above objects
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | ts_object <- tstools::initialize_ts_forecast_data(
data = dummy_gasprice,
date_col = "year_month",
col_of_interest = "gasprice",
group_cols = c("state", "oil_company"),
xreg_cols = c("spotprice", "gemprice")
) %>%
dplyr::filter(grouping == "state = New York & oil_company = CompanyA") %>%
tstools::transform_data_to_ts_object(seasonal_periods = 3)
ts_train_data <- split_ts_object(
ts_object = ts_object,
ts_split_date = 200101,
output = "train",
max_length = Inf
)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.