Niko24 Niko24 -4 years ago 129
R Question

How to fit a seasonal ARIMA model in R

I would like to fit a seasonal ARIMA model, where the season is every 24 hours.
But how do I include the 24-hours seasonal term in R? So far I have tried the following:

arima(y, order=c(0,0,2), seasonal=c(0,0,5), method = "ML")

But that is an ARIMA(0,0,2)(0,0,5)_12 model if I am correct, so I hope to get help with making it an ARIMA(0,0,2)(0,0,5)_24 model instead.

Answer Source

You need to include period= inside seasonal=list(order=..., period=...). If observations are hourly, use period=24L. If per second, use period=24*60*60, etc.


# reproducible example!
# download file from:
df <- read.csv('multiTimeline.csv', skip=3, header=FALSE, stringsAsFactors = FALSE)
names(df) <- c('Time','Searches')
df$Time <- as.POSIXlt.character(df$Time, tz='UTC',format = '%Y-%m-%dT%H')

plot(df, type='l')

m1 <- arima(x = df$Searches, 
            order = c(0L,0L,2L),
            seasonal=list(order=c(0L,0L,5L), period=24L )

> m1

arima(x = df$Searches, order = c(0L, 0L, 2L), seasonal = list(order = c(0L, 
    0L, 5L), period = 24L))

         ma1     ma2    sma1    sma2     sma3    sma4    sma5  intercept
      1.0827  0.6160  0.6155  0.1403  -0.1472  0.0104  0.6807    52.1477
s.e.  0.0631  0.0566  0.2305  0.2005   0.1445  0.2210  0.2176     2.4497

sigma^2 estimated as 35.69:  log likelihood = -575.94,  aic = 1169.88

See ?arima:

seasonal A specification of the seasonal part of the ARIMA model, plus the period (which defaults to frequency(x)). This should be a list with components order and period, but a specification of just a numeric vector of length 3 will be turned into a suitable list with the specification as the order.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download