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

Error forecast ARIMA with exogenous variables for short time series #412

Open
davide-coppola-sdg opened this issue Apr 9, 2024 · 0 comments

Comments

@davide-coppola-sdg
Copy link

I am having difficulties to forecast ARIMA model with exogenous variables.
Fitting of the model is not an issue, however when calling forecast on fitted ARIMA model with exogenous variables the whole process fails. I do not have rank problems with my exogenous variables.

The error I am receiving is :

`Error in `mutate()`:
ℹ In argument: `.mdl = (function (object, ...) ...`.
Caused by error in `as.matrix(newxreg) %*% coefs`:
! non-conformable arguments`

The issue I am having arises with a short time series. Here you can find a reproducible example with two time series, one works fine while the other raises the said issue calling forecast. The code uses as input data_weekly.csv .

I know that fitting an ARIMA model on short time series is not the best practice but I do not expect an error, just a not so precise model.

Thanks.

Example:

require(tidyverse)
require(dplyr)
require(ggplot2)
require(cowplot)
require(readr)
require(lubridate)
require(tsibble)
require(fable)
require(knitr)
require(ISOweek)
require(imputeTS)
require(Metrics)
require(timeDate)
require(log4r)
require(feasts)
require(future)
require(purrr)
require(furrr)
require(fst)

data <- read_csv('data_weekly.csv')

data <- data %>% 
  mutate(WEEK=yearweek(WEEK)) %>% 
  as_tsibble(key=c(PRODUCT, CLIENT), index=WEEK)

last_train_week <- yearweek("2024 W14")

# models training
weekly_model <- data %>%
  filter(WEEK<=last_train_week) %>% 
  model(.mdl=ARIMA(UNITS ~ Ex_var_1 + Ex_var_2 + Ex_var_3), greedy=TRUE))

# forecast working fine
weekly_forecast_right <- weekly_model %>%
  filter(PRODUCT=="AA", CLIENT=="BB") %>% 
  forecast(new_data=data %>% filter(WEEK>last_train_week))

# forecast raising error
weekly_forecast_wrong <- weekly_model %>%
  filter(PRODUCT=="XX", CLIENT=="YY") %>% 
  forecast(new_data=data %>% filter(WEEK>last_train_week))
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