I am using the forecast library for doing some time series forecasting. I need to forecast number of sold items. I am planning to add holidays as xreg in auto.arima. The holiday will be a 0/1 list, where 0 indicates no holiday and 1 indicates holiday. Holiday list has to be modeled in fourier package, which takes

fourier(x, K, h = NULL)

I am not sure how to calculate the correct value of K.

Can somebody point me to some source or some code for it in r?

This is some piece of code which I am using

holidayf <- c(0,0,0,0,0,1,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,1,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,1,0,0,0,1,1,1,1,1,0,0,0,0)
h <- length(holidayf)
#given holidays
holiday <- df[,2] 
y <- ts(df[,1],start = 2011,frequency = 52)
z <- fourier(y, K=k)
zf <- fourier(y, K=k, h=h)
fit <- auto.arima(y, xreg=cbind(z,holiday), seasonal=FALSE)
fc <- forecast(fit, xreg=cbind(zf,holidayf), h=h)
fc %>% autoplot()

  • 1
    $\begingroup$ See "Forecasting weekly data" and "Forecasting with daily data" by Rob J. Hyndman. $\endgroup$ – Richard Hardy Apr 16 '19 at 17:48
  • 1
    $\begingroup$ I don't understand the link between holidays and Fourier. if you have a list of 10 holidays then why not simply put 10 dummies? Fourier is overkill in this case, unless the holidays are very regular $\endgroup$ – Aksakal Feb 11 at 21:57

often times there are significant sales before on and after each holiday . often times individual days of the month are important ... sometimes week-of-the-month .. often long weekends have. There can be daily fixed effects, monthly effects. There can be level shifts and multiple trend changes. See https://autobox.com/capable.pdf slide 50- for more on modelling daily data.

K: is the Maximum order of Fourier terms or frequencies that you wish to specify .

If you wish you can post your data and I will try and help further .


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.