1

I am trying to fit an ARIMA model (fable package) where I include dummies. Here is the code I am using

mod_region <- aggregated_region %>% 
  filter(SETTLEMENTDATE < '2020-02-11') %>% 
  model( 
    arima = ARIMA(sum ~ as.factor(Day))
  )
fc_region <- mod_region %>% 
  forecast(h='7 days’)

It gives this error:

“Error: object 'Day' not found Unable to compute required variables from provided new_data. Does your model require extra variables to produce forecasts?”

I tried looking up on google but couldn’t figure out anything.

I earlier thought maybe it’s creating 7 dummies and that’s why the code blows up and then I tested using arima = ARIMA(sum ~ I(Day == ’Sunday’)) But it gives the same error at the time of using forecast() function.

Do you know why this might be happening?

  • Try creating your factor variable before calling the model function. – Rob Hyndman Apr 07 '20 at 23:30
  • @RobHyndman Thanks for that Rob. I tried doing that. It now gives this error `[5] variable lengths differ (found for 'xreg')` – adelaide_user_1009 Apr 08 '20 at 20:15
  • Please provide a reproducible example. – Rob Hyndman Apr 08 '20 at 22:08
  • @RobHyndman I have uploaded some data into the file here (https://drive.google.com/file/d/1ZI95SnJOTVVtbil84eq7n1F5mei5GeJL/view?usp=sharing) and I am using this code: – adelaide_user_1009 Apr 10 '20 at 12:29
  • @RobHyndman `aggregated_region <- readRDS('aggregated_region.rds') aggregated_region_train <- aggregated_region %>% filter(Date < '2020-02-11') xreg_region_new_m <- aggregated_region %>% filter(Date >= '2020-02-11') xreg_region <- as.factor(aggregated_region_train$Day) xreg_region_new <- as.factor(xreg_region_new_m$Day) mod_region <- aggregated_region_train %>% model( arima = ARIMA(sum ~ xreg_region) ) fc_region <- mod_region %>% forecast(h='7 days', newdata = xreg_region_new)` – adelaide_user_1009 Apr 10 '20 at 12:31

1 Answers1

2

First, you need to create the variables before modelling. So add the factor version of Day before calling the model function.

Second, you need all variables in the tsibble, not as separate objects as per the comments.

The following code will work with your data.

library(tidyverse)
library(tsibble)
library(fable)
aggregated_region <- readRDS('aggregated_region.rds') %>%
  mutate(Day = as.factor(Day))
train <- aggregated_region %>% 
  filter(Date < '2020-02-11')
test <- aggregated_region %>% 
  filter(Date >= '2020-02-11') 

mod_region <- train %>% 
  model(arima = ARIMA(sum ~ Day)) 
fc_region <- mod_region %>% 
  forecast(new_data = test)
Rob Hyndman
  • 30,301
  • 7
  • 73
  • 85