Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ARIMA forecasts don't work for x weekly, monthly and quarterly data where x > 1 #392

Open
bottervanger opened this issue Apr 13, 2023 · 1 comment

Comments

@bottervanger
Copy link

bottervanger commented Apr 13, 2023

See reprex below.

The calculation of fc_start seems to be wrong.

fc_start <- object$tsp$range[2]+round(as.numeric(diff(object$tsp$range)+1)/nrow(object$est), 6)

From what I can tell it's doing:
fc_start <- <last index value> + (<time diff between start and end> + 1 ) / <no of samples>
while it should be:
fc_start <- <last index value> + <time diff between start and end> / <no of intervals>
or, equivalently:
fc_start <- <last index value> + <time diff between start and end> / (<no of samples> - 1)

data <- tsibble::tsibble(
    week = (lubridate::today() + lubridate::period(weeks = seq(1, 9, 4))) |>
        tsibble::yearweek(),
    number = 1:3,
    index = week
)
data |>
    fabletools::model(arima = fable::ARIMA(number ~ pdq() + PDQ())) |>
    fabletools::forecast(h = 1)
#> Error in `mutate()`:
#> ! Problem while computing `arima = (function (object, ...) ...`.
#> Caused by error in `forecast()`:
#> ! Forecasts from an ARIMA model must start one step beyond the end of the trained data.

#> Backtrace:
#>      ▆
#>   1. ├─fabletools::forecast(...)
#>   2. ├─fabletools:::forecast.mdl_df(...)
#>   3. │ └─dplyr::mutate_at(...)
#>   4. │   ├─dplyr::mutate(.tbl, !!!funs)
#>   5. │   └─dplyr:::mutate.data.frame(.tbl, !!!funs)
#>   6. │     └─dplyr:::mutate_cols(.data, dplyr_quosures(...), caller_env = caller_env())
#>   7. │       ├─base::withCallingHandlers(...)
#>   8. │       └─mask$eval_all_mutate(quo)
#>   9. ├─fabletools (local) `<fn>`(...)
#>  10. └─fabletools:::forecast.lst_mdl(...)
#>  11.   └─fabletools:::mapply_maybe_parallel(...)
#>  12.     └─base::mapply(FUN = .f, ..., MoreArgs = MoreArgs, SIMPLIFY = SIMPLIFY)
#>  13.       ├─fabletools (local) `<fn>`(dots[[1L]][[1L]], dots[[2L]][[1L]], h = 1, point_forecast = `<named list>`)
#>  14.       └─fabletools:::forecast.mdl_ts(...)
#>  15.         ├─fabletools::forecast(...)
#>  16.         └─fable:::forecast.ARIMA(object$fit, new_data, specials = specials, times = times, ...)
#>  17.           └─rlang::abort("Forecasts from an ARIMA model must start one step beyond the end of the trained data.")

Created on 2023-04-13 with reprex v2.0.2

Edit: wrap text in code to prevent angle brackets being swallowed
Edit: add missing term to calculation interpretation

@bottervanger
Copy link
Author

The calculation of fc_start seems to work if you use an interval of single weeks, months, quarters, but not for anything else.

@bottervanger bottervanger changed the title wrong fc_start for weekly (and I guess monthly and quarterly data) ARIMA forecasts using horizon don't work for x weekly, monthly and quarterly data where x > 1 Apr 14, 2023
@bottervanger bottervanger changed the title ARIMA forecasts using horizon don't work for x weekly, monthly and quarterly data where x > 1 ARIMA forecasts don't work for x weekly, monthly and quarterly data where x > 1 Apr 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant