-1

I have fitted an ARIMA model using the fable R package. When I go to use the model to forecast the distribution using bootstrap resampled errors it returns all NAs.

ARIMA_model <- targets %>%
  as_tsibble(key = 'key', index = 'time') %>%
  model(ARIMA(y ~ x))

ARIMA_fable <- ARIMA_model %>%
  generate(new_data = scenarios, bootstrap = TRUE, times = 100)

I can get it to run using forecast() but I want to see each ensemble member and the errors are not expected to be normally distributed.

ARIMA_fable <- ARIMA_model %>% forecast(new_data = scenarios, bootstrap = FALSE)

Here is a reproducible example:

key <- c('A', 'B', 'C')
time <- seq(start, by = 1, length.out = 15)

set.seed(123)


targets <- expand.grid(time = time, key = key) %>%
  mutate(x = sort(runif(45, 0, 30)),
         y = sort(runif(45, 0, 30)))

ARIMA_model <- targets %>%
  as_tsibble(key = 'key', index = 'time') %>%
  model(ARIMA(y ~ x))

test_scenarios <- targets %>%
  mutate(time = time + lubridate::days(16),
         x = sort(runif(45, 0, 30)),
         y = sort(runif(45, 0, 30))) %>%
  as_tsibble(key = 'key', index = 'time')

ARIMA_model %>%
  forecast(new_data = test_scenarios, bootstrap = T)

1 Answers1

0

I still can't reproduce the NA forecasts that you get, however I have identified and fixed an issue in the code that could be causing issues here (https://github.com/tidyverts/fable/commit/685cc9ec7846a990d7c664f8eb24e4ad75e1673a).

This updated version can be installed with remotes::install_github("tidyverts/fable"), and with this version I am able to run the example you provided without issue:

library(fable)
#> Loading required package: fabletools
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
key <- c('A', 'B', 'C')
time <- seq(Sys.Date(), by = 1, length.out = 15)

set.seed(123)

targets <- expand.grid(time = time, key = key) %>%
  mutate(x = sort(runif(45, 0, 30)),
         y = sort(runif(45, 0, 30)))

ARIMA_model <- targets %>%
  as_tsibble(key = 'key', index = 'time') %>%
  model(ARIMA(y ~ x))

test_scenarios <- targets %>%
  mutate(time = time + lubridate::days(16),
         x = sort(runif(45, 0, 30)),
         y = sort(runif(45, 0, 30))) %>%
  as_tsibble(key = 'key', index = 'time')

ARIMA_model %>%
  forecast(new_data = test_scenarios, bootstrap = T)
#> # A fable: 45 x 6 [1D]
#> # Key:     key, .model [3]
#>    key   .model       time                  y .mean     x
#>    <fct> <chr>        <date>           <dist> <dbl> <dbl>
#>  1 A     ARIMA(y ~ x) 2022-10-02 sample[5000]  10.2  1.82
#>  2 A     ARIMA(y ~ x) 2022-10-03 sample[5000]  11.1  2.73
#>  3 A     ARIMA(y ~ x) 2022-10-04 sample[5000]  11.6  2.81
#>  4 A     ARIMA(y ~ x) 2022-10-05 sample[5000]  11.9  3.92
#>  5 A     ARIMA(y ~ x) 2022-10-06 sample[5000]  12.3  4.26
#>  6 A     ARIMA(y ~ x) 2022-10-07 sample[5000]  13.0  4.27
#>  7 A     ARIMA(y ~ x) 2022-10-08 sample[5000]  13.3  4.41
#>  8 A     ARIMA(y ~ x) 2022-10-09 sample[5000]  14.3  4.63
#>  9 A     ARIMA(y ~ x) 2022-10-10 sample[5000]  15.2  5.63
#> 10 A     ARIMA(y ~ x) 2022-10-11 sample[5000]  15.6  6.59
#> # … with 35 more rows

Created on 2022-09-16 by the reprex package (v2.0.1)