2
$\begingroup$

I have a question related to the estimation of arima models in R. I have estimated a model with daily simulated data where Mondays have a lower value than the rest of the days. I have simulated two years of data, and I want to predict the next year.

According to the data, I should obtain an estimation which has lower values on Mondays, but I get it on Tuesdays... It seems the data has been desplaced one day. I show my code.

library(ggplot2)
library(forecast)
library(lubridate)

date <- seq(as.Date('2018-01-01'),as.Date('2019-12-31'),by='day')
orders <- rnorm(length(date),100,10)
s <- seq(1,length(date),by=7)
for(i in s)
{
  orders[i] <- orders[i]-rnorm(1,70,10)
}

datos <- data.frame(date = date,orders = orders)

ggplot()+
  geom_line(data = datos, aes(x = date, y = orders))

datos begins on Monday 2018-01-01. Every Monday has a lower value. Now I estimate the model with the corresponding seasonal periods.

orders_ts <- msts(datos$orders,seasonal.periods = c(7,365.25),start = decimal_date(as.Date("2018-01-01")))

model <- auto.arima(orders_ts,trace = T,D=1)
pred <- forecast(model,h=365)
plot(pred)

pred_tabla <- as.data.frame(pred)
date_pred <- as.Date(time(rownames(pred_tabla)), origin = "2019-12-31")
rownames(pred_tabla) <- date_pred
pred_tabla <- dplyr::select(pred_tabla,c('Point Forecast'))
colnames(pred_tabla) <- 'Prediction'
head(pred_tabla,50)

           Prediction
2020-01-01   89.65607
2020-01-02  127.10014
2020-01-03  104.69489
2020-01-04  104.82119
2020-01-05   90.43497
2020-01-06  119.54629
2020-01-07   28.30212
2020-01-08   76.84848
2020-01-09   89.47474
2020-01-10  108.30905
2020-01-11  108.61325
2020-01-12   79.79830
2020-01-13   82.68802
2020-01-14   30.47466
2020-01-15   83.57336
2020-01-16  104.82201
2020-01-17   94.73705
2020-01-18   97.66296
2020-01-19   94.98595
2020-01-20   99.00874
2020-01-21   43.39133
2020-01-22  110.69250
2020-01-23   99.88973
2020-01-24   91.25167
2020-01-25   86.29674
2020-01-26   99.76741
2020-01-27   96.38425
2020-01-28   17.60269
2020-01-29   99.22064
2020-01-30  116.89777
2020-01-31  114.49706
2020-02-01  108.64221
2020-02-02  114.64886
2020-02-03   88.54560
2020-02-04   17.62015
2020-02-05  101.96455
2020-02-06   97.18976
2020-02-07  100.91465
2020-02-08   94.81816
2020-02-09  103.15029
2020-02-10  100.13627
2020-02-11   32.48818
2020-02-12   97.34060
2020-02-13   99.69957
2020-02-14   82.02583
2020-02-15   89.17326
2020-02-16   93.99973
2020-02-17   98.01702
2020-02-18   34.04982
2020-02-19   91.95284

Now the lower values are on Tuesdays, in 2020-01-07, 2020-01-14, etc.

Could someone give me an answer of why this is happening? And how could I solve this?

Thank you very much!

$\endgroup$

1 Answer 1

0
$\begingroup$

The issue is the combination of annual and day of week seasonality. If you remove the 365.25 from the frequency it forecasts correctly. This combination may not play nicely together with the weeks of the year not aligning. The simulation of the data gives no reason to have the annual seasonality anyway.

$\endgroup$
2
  • $\begingroup$ Yes, but if I do this, I cannot compare the days of 2020 with the days of 2019. Imagine I have a high value one day of 2019, then I will want to have the same peak in the same day of 2020. $\endgroup$
    – Robert Sun
    Dec 19, 2019 at 16:12
  • $\begingroup$ Agreed, but I would challenge you on the wisdom of doing that. Granted - I assume you have some real data that I don't know anything about, but per the example you provided there is no reason to think that utilizing the previous year value will improve the forecast. You could just use 365.25 as your seasonal frequency if you really want this capability. $\endgroup$ Dec 19, 2019 at 17:12

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.