尝试改装 ARIMA 模型时出现以下错误。
new_model <- Arima(data,model=old_model)
Error in Ops.Date(driftmod$coeff[2], time(x)) :
* not defined for "Date" objects
注:数据类别为zoo
。我也尝试过使用xts
,但我得到了同样的错误。
编辑:正如 Joshua 所建议的,这里是可重现的例子。
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)