Reputation: 1655
I am getting the following error when I try to refit the ARIMA model.
new_model <- Arima(data,model=old_model)
Error in Ops.Date(driftmod$coeff[2], time(x)) :
* not defined for "Date" objects
Note: The class of data is zoo
. I also tried using xts
, but I got the same error.
Edit: As suggested by Joshua, here is the reproducible example.
library('zoo')
library('forecast')
#Creating sample data
sample_range <- seq(from=1, to=10, by=1)
x<-sample(sample_range, size=61, replace=TRUE)
ts<-seq.Date(as.Date('2017-03-01'),as.Date('2017-04-30'), by='day')
dt<-data.frame(ts=ts,data=x)
#Split the data to training set and testing set
noOfRows<-NROW(dt)
trainDataLength=floor(noOfRows*0.70)
trainData<-dt[1:trainDataLength,]
testData<-dt[(trainDataLength+1):noOfRows,]
# Use zoo, so that we get dates as index of dataframe
trainData.zoo<-zoo(trainData[,2:ncol(trainData)], order.by=as.Date((trainData$ts), format='%Y-%m-%d'))
testData.zoo<-zoo(testData[,2:ncol(testData)], order.by=as.Date((testData$ts), format='%Y-%m-%d'))
#Create Arima Model Using Forecast package
old_model<-Arima(trainData.zoo,order=c(2,1,2),include.drift=TRUE)
# Refit the old model with testData
new_model<-Arima(testData.zoo,model=old_model)
Upvotes: 1
Views: 265
Reputation: 176648
The ?Arima
page says that y
(the first argument) should be a ts
object. My guess is that the first call to Arima
coerces your zoo
object to ts
, but the second call does not.
An easy way to work-around this is to explicitly coerce to ts
:
# Refit the old model with testData
new_model <- Arima(as.ts(testData.zoo), model = old_model)
Upvotes: 1