Solved – ARIMA double seasonality with dumthe in R error xreg

arimar

I'm playing with hourly univariate data and try to fit an arima model with more than one seasonality (daily, weekly) using a dummy for the weekly seasonality. I found a very good post explaining a similar problem but after many trials I'm running out of ideas with the following error:

Error in optim(init[mask], armaCSS, method = optim.method, hessian = FALSE,  : 
  non-finite value supplied by optim

My code is the following:

library(lubridate)
start=dmy_hms("25/02/2011 00:00:00")
index=start + c(0:1000) * hours(1)
week = wday(index)
xreg_w = model.matrix(~0+as.factor(week))
colnames(xreg_w) = c("Mon","Tue","Wed","Thu","Fri","Sat","Sun")

freq=24
set.seed(1234)
y=ts(log(35+10*rnorm(1001)),f=freq)

library(forecast)
model = Arima(y, order=c(0,0,0), seasonal=list(order=c(1,0,0), period=24), 
              xreg=xreg_w)

Best Answer

Your xreg_w matrix contains dummy variables for all seven days, but you only need six days due to the inclusion of a constant in your ARIMA model. Thus, the design matrix is not of full rank. Either leave the constant out, or use only six days.

This will work:

model <- Arima(y, order=c(0,0,0), seasonal=list(order=c(1,0,0), period=24), 
              xreg=xreg_w, include.mean=FALSE)

Or this (using only six days):

xreg_w <- seasonaldummy(ts(y,f=7))
model <- Arima(y, order=c(0,0,0), seasonal=list(order=c(1,0,0), period=24), 
              xreg=xreg_w)