ARIMA forecasts don't work for x weekly, monthly and quarterly data where x > 1
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 588
- Forks
- 71
- Avg merge
- 1h 58m
- Merged PRs (30d)
- 1
Description
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
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the fc_start calculation shown in the issue and reproduce the failure using the provided tsibble, ARIMA model, and forecast call. Trace why the forecast does not start one step beyond the trained data, then verify that weekly, monthly, and quarterly data with x > 1 forecast successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- data
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100