3

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)
nopeva
  • 497
  • 5
  • 15

1 Answers1

7

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)
Rob Hyndman
  • 51,928
  • 23
  • 126
  • 178
  • thanks very much for your answer and for the packages. On first thoughts it seems a bit unnatural to leave the constant out, but what do you think is best? – nopeva Mar 17 '13 at 11:11
  • if I add more dummies, the first column of every new dummy will be added to the arima constant right? so the more dummies we include the less information we get about their weights if we stick with the constant in the model, is this correct? – nopeva Mar 17 '13 at 11:30
  • If you have more factors to include, you will need to use the second solution. You don't lose information. You just have to interpret the coefficients as relative to the missing level. – Rob Hyndman Mar 17 '13 at 12:22
  • thanks again, I will cbind the two dummies using your neat seasonaldummy() function! – nopeva Mar 17 '13 at 12:33