The forecast function of the fabletools package in my R produces an error when running the following code (or in fact running any code):
fcs_1 <-
train_1 %>%
model(
ARIMA_212 = ARIMA(value ~ 0 + pdq(2,1,2) + PDQ(0,0,0)),
ARIMA_211 = ARIMA(value ~ 0 + pdq(2,1,1) + PDQ(0,0,0)),
ARIMA_112 = ARIMA(value ~ 0 + pdq(1,1,2) + PDQ(0,0,0)),
ARIMA_210 = ARIMA(value ~ 0 + pdq(2,1,0) + PDQ(0,0,0)),
ARIMA_012 = ARIMA(value ~ 0 + pdq(0,1,2) + PDQ(0,0,0))
) %>%
fabletools::forecast(test_1)
train_1 is a tsibble of the following format:
index value
<mth> <dbl>
1 1950 Jan 5.82
2 1950 Apr 8.30
3 1950 Jul 13.4
4 1950 Okt 15.7
5 1951 Jan 15.6
6 1951 Apr 13.4
The error is:
Error in `mutate()`:
! Problem while computing `ARIMA_212 = (function (object, ...) ...`.
Caused by error in `validObject()`:
! ungültiges Objekt der Klasse “Period”: periods must have integer values
The full backtrace looks like this:
▆
1. ├─fcs_1 %>% forecast(test_1)
2. ├─fabletools::forecast(., test_1)
3. ├─fabletools:::forecast.mdl_df(., test_1)
4. │ └─dplyr::mutate_at(...)
5. │ ├─dplyr::mutate(.tbl, !!!funs)
6. │ └─dplyr:::mutate.data.frame(.tbl, !!!funs)
7. │ └─dplyr:::mutate_cols(.data, dplyr_quosures(...), caller_env = caller_env())
8. │ ├─base::withCallingHandlers(...)
9. │ └─mask$eval_all_mutate(quo)
10. ├─fabletools (local) `<fn>`(...)
11. ├─fabletools:::forecast.lst_mdl(...)
12. │ └─fabletools:::mapply_maybe_parallel(...)
13. │ └─base::mapply(FUN = .f, ..., MoreArgs = MoreArgs, SIMPLIFY = SIMPLIFY)
14. │ ├─fabletools (local) `<fn>`(dots[[1L]][[1L]], dots[[2L]][[1L]], h = NULL, point_forecast = `<named list>`)
15. │ └─fabletools:::forecast.mdl_ts(...)
16. │ ├─fabletools::forecast(...)
17. │ └─fable:::forecast.ARIMA(...)
18. │ └─vctrs:::`+.vctrs_vctr`(...)
19. │ ├─vctrs::vec_arith("+", e1, e2)
20. │ ├─tsibble:::vec_arith.yearmonth("+", e1, e2)
21. │ └─tsibble:::vec_arith.yearmonth.numeric("+", e1, e2)
22. │ ├─tsibble:::new_yearmonth(as_date(x) + period(months = y))
23. │ │ └─vctrs::new_vctr(x, class = "yearmonth")
24. │ │ └─rlang::is_vector(.data)
25. │ └─lubridate::period(months = y)
26. │ └─lubridate:::.period_from_units(list(...))
27. │ └─methods::new(...)
28. │ ├─methods::initialize(value, ...)
29. │ └─lubridate (local) initialize(value, ...)
30. │ └─methods::validObject(.Object)
31. │ └─base::stop(msg, ": ", errors, domain = NA)
32. └─base::.handleSimpleError(...)
33. └─dplyr (local) h(simpleError(msg, call))
34. └─rlang::abort(...)
Newest version of RStudio and all required packages are installed, the same code used to previously work on my machine.
test_1 has exactly the same format as train_1 (was created as an 80/20 slice), up until yesterday forecasting like this worked fine. I have not (consciously) made any changes to my R installation, packages or RStudio.
edit: dput(train_1):
structure(list(index = structure(c(-7305, -7215, -7124, -7032,
-6940, -6850, -6759, -6667, -6575, -6484, -6393, -6301, -6209,
-6119, -6028, -5936, -5844, -5754, -5663, -5571, -5479, -5389,
-5298, -5206, -5114, -5023, -4932, -4840, -4748, -4658, -4567,
-4475, -4383, -4293, -4202, -4110, -4018, -3928, -3837, -3745,
-3653, -3562, -3471, -3379, -3287, -3197, -3106, -3014, -2922,
-2832, -2741, -2649, -2557, -2467, -2376, -2284, -2192, -2101,
-2010, -1918, -1826, -1736, -1645, -1553, -1461, -1371, -1280,
-1188, -1096, -1006, -915, -823, -731, -640, -549, -457, -365,
-275, -184, -92, 0, 90, 181, 273, 365, 455, 546, 638, 730, 821,
912, 1004, 1096, 1186, 1277, 1369, 1461, 1551, 1642, 1734, 1826,
1916, 2007, 2099, 2191, 2282, 2373, 2465), class = c("yearmonth",
"vctrs_vctr")), value = c(5.82371992601844, 8.30302536605984,
13.4214589164561, 15.7125977565162, 15.6467375609683, 13.4166172427643,
11.4541306698285, 10.1695120006194, 14.5649845400126, 18.9324892528569,
21.0311963012277, 20.7291593132272, 18.8215292015661, 16.4935102105858,
14.814017999784, 13.9694717789116, 9.82170442830894, 6.85813970690365,
8.70501086394644, 13.0619335668232, 14.2341673784712, 13.554624906916,
9.23481859610119, 9.48483298576991, 7.88781982671861, 7.91935043659087,
7.786176025347, 8.42168659318232, 11.6814500569844, 12.4902260823034,
12.8754637489436, 12.2568216199864, 12.3946650719287, 12.3962513506109,
11.9768753418986, 9.3432412689745, 7.29034525063435, 5.77751442415736,
5.24731159347495, 1.13975401292387, -2.3434572782195, -6.18665301156307,
-6.84818912036291, -4.9876580356317, -3.25211274065144, -4.75318559054628,
-4.94374771348456, -4.92201462025638, -3.57351803911329, -1.96844815847518,
-3.16205037807184, -6.48434609123239, -6.96274218928273, -7.37969967012606,
-8.37636248995215, -9.50779058136715, -9.93511990279183, -10.4514524557227,
-8.142510526086, -8.12645393226429, -6.39028069127383, -6.59027573877132,
-8.96558759243726, -7.66526019670935, -5.92710903952333, -2.05072774543544,
-3.71907613554461, -3.741422612841, -3.10432931924714, -2.25393531307098,
-0.685497132992526, 3.00665444094586, 4.88417082385038, 4.16502957225296,
3.76000201169048, 2.79009792483155, 4.79810855545285, 10.7177350806015,
9.19623695663269, 3.43760454129163, -0.757291304488621, 0.0936896791076991,
0.324019107470589, -1.30691639896979, -1.68151731567895, 0.301462508682856,
4.07460747502974, 7.67720152110724, 7.94014431117869, 5.48370526276104,
3.42686580082702, 4.30370864739371, 4.29048541367606, 4.33856662672821,
3.80838075344403, 4.97881533902019, 5.37820857511111, 6.81543523832141,
6.19212607137755, 6.26567099265801, 5.62381720731494, 7.58321556276516,
7.49130201237245, 8.35730865876876, 5.70461610612163, 4.89985658587265,
1.97228599326616, -1.47518055997003)), class = c("tbl_ts", "tbl_df",
"tbl", "data.frame"), row.names = c(NA, -108L), key = structure(list(
.rows = structure(list(1:108), ptype = integer(0), class = c("vctrs_list_of",
"vctrs_vctr", "list"))), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -1L)), index = structure("index", ordered = TRUE), index2 = "index", interval = structure(list(
year = 0, quarter = 0, month = 3, week = 0, day = 0, hour = 0,
minute = 0, second = 0, millisecond = 0, microsecond = 0,
nanosecond = 0, unit = 0), .regular = TRUE, class = c("interval",
"vctrs_rcrd", "vctrs_vctr")))
dput(test_1):
structure(list(index = structure(c(2557, 2647, 2738, 2830, 2922,
3012, 3103, 3195, 3287, 3377, 3468, 3560), class = c("yearmonth",
"vctrs_vctr")), value = c(-1.16296077223469, 0.714453744174292,
2.97622897489834, 2.18463064503787, 0.462940207095485, -0.587134702282295,
1.63693772377973, 3.60378919185492, 2.58944214429125, 3.69102058402099,
5.74637935987533, 6.91046603481904)), class = c("tbl_ts", "tbl_df",
"tbl", "data.frame"), row.names = c(NA, -12L), key = structure(list(
.rows = structure(list(1:12), ptype = integer(0), class = c("vctrs_list_of",
"vctrs_vctr", "list"))), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -1L)), index = structure("index", ordered = TRUE), index2 = "index", interval = structure(list(
year = 0, quarter = 0, month = 3, week = 0, day = 0, hour = 0,
minute = 0, second = 0, millisecond = 0, microsecond = 0,
nanosecond = 0, unit = 0), .regular = TRUE, class = c("interval",
"vctrs_rcrd", "vctrs_vctr")))
Fixed it, for whatever reason, the training and testing dataset required to be recast as tsibbles again before modeling (which is strange as they had been tsibbles already).