5
$\begingroup$

Per this post, you can force seasonality in auto.arima by selecting D=1.

I have a weekly time series which looks like it might (or might not) have a seasonal component (I have a priori reasons for thinking it might have a seasonal component).

Data <- as.ts(Data$Sales,order.by=Data$Date, frequency=52) 
Train <- window(Data,start=3,end=107)
Test <- window(Data,start=108,end=116)

I tried manually fitting a seasonal model:

fit <- arima(Train, order=c(2,0,1) , seasonal = list (order= c(0,1,0) , period = 52))
forec <- predict(fit, n.ahead =8)

gave an "OK" forecast (see first graph).

enter image description here

So I tried improving on it by using auto.arima to find the best model.

AutoFit <- auto.arima(Train)

This returned an ARIMA(1,1,1) model, which I then fit using:

#fit <- arima(Train, order=c(1,1,1))

But this gave worse results than the seasonal model I selected manually (see second graph). enter image description here

So I tried to force seasonality by running:

AutoFit <- auto.arima(Train, D=1)

But I still get the same ARIMA(1,1,1) model.

Why is auto.arima not trying to fit a seasonal model, even why I try to force it?

I've also tried:

AutoFit <- auto.arima(Train, seasonal=TRUE, D=1)

and

AutoFit <- auto.arima(Train, seasonal=TRUE, start.P=0, start.Q=0 , D=1)
$\endgroup$
7
+100
$\begingroup$

Rule number 1: when your code does not do what you want, start inspecting your objects.

library(forecast)
set.seed(1)
(Data <- as.ts(rnorm(116), frequency=52) )

yields

Time Series:
Start = 1 
End = 116 
Frequency = 1
...snip...

Note that Frequency is 1, not 52, as we explicitly set above!

The problem is that as.ts() silently ignores the frequency parameter and sets the frequency to 1. Here is the help page to stats::ts():

 ‘as.ts’ is generic.  Its default method will use the ‘tsp’
 attribute of the object if it has one to set the start and end
 times and frequency.

So, if you want something seasonal, either supply an x with a tsp attribute to as.ts()... or use ts() straight from the beginning.

set.seed(1)
(Data <- ts(rnorm(116), frequency=52) )

which yields

Time Series:
Start = c(1, 1) 
End = c(3, 12) 
Frequency = 52
...snip...

This looks much better. Note that we now need to supply 2-vectors to window(), corresponding to the Start and End attributes of Data:

Train <- window(Data,start=c(1,1),end=c(2,52))
auto.arima(Train, D=1)

which yields a nice seasonal ARIMA model, as required:

Series: Train 
ARIMA(0,0,0)(0,1,0)[52]
$\endgroup$
2
$\begingroup$

Two things come to mind 1) it is silly to try and fit a seasonal ar model of order 52 to 105 obvservations as you only have 2 cycles of data and 2) see I have correlogram ACF and PACF below for a temperature time series. Can I say it is MA(2) from ACF? What about AR? where ignoring the effect of anomalies is discussed causing a flaw in model identification

$\endgroup$
  • 2
    $\begingroup$ "it is silly to try and fit a seasonal ar model of order 52 to 105 obvservations as you only have 2 cycles of data" : I have a priori reasons for thinking my data might be seasonal, which is why I am trying a seasonal model even though I only have 2 years worth. Based on the graphs the seasonal does seem to work better. $\endgroup$ – Skander H. Dec 29 '17 at 12:47
  • 2
    $\begingroup$ You might try estimating a model including lag 52 and follow stats.stackexchange.com/questions/319254/… for ways to improve that model . Alternatively you might set up a regression model with 51 weekly dummies and again consider model modifications per the url I cited. To a large degree due to the paucity of data , one needs to employ alternative approaches to construct a useful model and not depend on pseudo-automatic approaches designed for larger sample sizes like 10 years of weekly data.. $\endgroup$ – IrishStat Dec 29 '17 at 13:17

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.