1

I'm trying out top-down method for forecasting demand of products in a retail store.

fourier_forecasts = forecast(sales_weekly_hts, h=12,method="tdfp", FUN=function(x) auto.arima(x, xreg=fourier(x, K=12), seasonal=FALSE))

sales_weekly_hts is an hts object containing 2.5 years of weekly sales data.

It gives me the error :-

"Error in forecast.Arima(models, h = h) : No regressors provided"

I'm guessing that error is because its not able to obtain the fourier terms for out of sample forecast but I don't get how to resolve this. Is it not able to know how many periods to forecast into the future?

Minimum reproducible example:-

library(dplyr)
library(hts)

# creating a time series matrix containing 4 series and 133 weeks random data 
min_rep_eg = matrix(data = rnorm(n = 133*4 ,mean = 2), nrow = 133, ncol = 4) %>% ts(frequency = 365.25/7)

# giving names to the 5 time series. These names are used to create the hierarchy.
colnames(min_rep_eg) = c("10011001","10011003","10031021","10031031")

# creating the hts.
min_rep_eg_hts = hts(min_rep_eg, characters = c(4, 4))

min_rep_eg_hts_fc = forecast(min_rep_eg_hts, h=2,method="tdfp", FUN=function(x) auto.arima(x, xreg=fourier(x, K=12), seasonal=FALSE))
Goutham
  • 53
  • 6
  • Hi, please [provide data](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610), e.g. adding the output of `dput()` or `dput(head())` to your question. You'll have a much better chance of getting a great answer! – jay.sf Feb 11 '19 at 13:26
  • Maybe try to consider fewer Fourier terms (i.e. decrease `K`)? Lower `K` means less complexity of your seasonal pattern. By decreasing `K`, you decrease the frequency of sine and cosine pairs that your model uses to approximate the seasonal pattern. – NRLP Feb 11 '19 at 14:11
  • Also, it may be worthwhile to check whether it makes lots of sense to forecast your sales data weekly - maybe monthly aggregates lead to less noise? – NRLP Feb 11 '19 at 14:26
  • @jay.sf dput gives me a huge amount of output would be too much to paste here. I'll try to write more about the data. – Goutham Feb 12 '19 at 05:44
  • @Luminita I chose a K value my minimized Aicc. Also model with relatively higher K value gives me visually more correct forecast. and as for your second question, I wanted to use monthly however I would end up with just 33 data points probably too less to make a good forecast. But I guess noise shouldn't be a problem in hierarchical forecasting, at higher levels of hierarchy I am able to discern seasonal patterns visually (it's still a bit noisy) – Goutham Feb 12 '19 at 05:49
  • 1
    added a minimum reproducible example – Goutham Feb 12 '19 at 06:24

1 Answers1

1

I just saw your post now. As your are using the auto.arima function, the easiest way to solve your problem is to use the arima model via the fmethod argument. Then, to set the value of external regressors via xreg and newxreg.

Taking your reproducible example :

library(dplyr)
library(hts)

# creating a time series matrix containing 4 series and 133 weeks random data 
min_rep_eg = matrix(data = rnorm(n = 133*4 ,mean = 2), nrow = 133, ncol = 4) %>% ts(frequency = 365.25/7)

# giving names to the 5 time series. These names are used to create the hierarchy.
colnames(min_rep_eg) = c("10011001","10011003","10031021","10031031")



# creating the hts.
min_rep_eg_hts = hts(min_rep_eg, characters = c(4, 4))
x=allts(min_rep_eg_hts)[,1]



min_rep_eg_hts_fc = forecast(min_rep_eg_hts, h=1,method="tdfp", fmethod ="arima",xreg=fourier(x, K=12),newxreg=tail(fourier(x, K=12),1))

Output :

enter image description here