Working on a time series of monthly labor data in the USA. If the forecast is set to 1 month, then this returns a warning message, but 3 months does not return a warning message.
Get the data, set the parameters:
time_series_data <- read.csv('https://raw.githubusercontent.com/InfiniteCuriosity/forecasting_jobs/main/Total_Nonfarm.csv')
train_amount <- 0.60
fc <- 1
Here is what the data looks like:
Load packages that will be used:
library(tidyverse)
library(fpp3)
Convert time series data to a tsibble:
time_series_data <- time_series_data %>%
dplyr::mutate(Date = tsibble::yearmonth(Label), Value = Value, Change = tsibble::difference(Value)) %>%
dplyr::select(Date, Value, Change) %>%
tsibble::as_tsibble(index = Date) %>%
dplyr::slice(-c(1))
Set up train and test sets:
time_series_train <- time_series_data[1:round(train_amount*(nrow(time_series_data))),]
time_series_test <- time_series_data[(round(train_amount*(nrow(time_series_data))) +1):nrow(time_series_data),]
Create a simple model, calculate error amounts (the same warning message happens with many different time series functions, such as ETS, ARIMA, etc.)
Linear1_model = fable::TSLM(Value ~ season() + trend())
Linear1_error_list <- time_series_train %>%
fabletools::model(fable::TSLM(Value ~ season() + trend())) %>%
fabletools::forecast(h = fc) %>%
fabletools::accuracy(time_series_test)
If fc = 1. it runs but returns the warning message:
# A tibble: 1 × 10
.model .type ME RMSE MAE MPE MAPE MASE RMSSE ACF1
<chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 fable::TSLM(Value ~ season() + trend()) Test 5998. 5999. 5998. 4.14 4.14 NaN NaN -0.131
Warning message:
1 error encountered
[1] subscript out of bounds
but if fc = 3 it runs but is no warning message.
The same warning message is returned no matter which values are selected. For example, this does not return the NA values, but also returns the warning message:
Linear1_error_list <- time_series_train %>%
fabletools::model(fable::TSLM(Value ~ season() + trend())) %>%
fabletools::forecast(h = fc) %>%
fabletools::accuracy(time_series_test) %>%
select(.model:MAPE)
Warning message:
1 error encountered
[1] subscript out of bounds
How can this run with fc = 1 and not return a warning message?
