【问题标题】:Error while refitting ARIMA model重新拟合 ARIMA 模型时出错
【发布时间】:2017-09-20 23:33:32
【问题描述】:

我在尝试改装 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)

【问题讨论】:

  • 您能否提供一个reproducible example,包括library() 对您正在使用的软件包的调用?
  • @JoshuaUlrich 抱歉耽搁了。我刚刚发布了一个可重现的示例。

标签: r xts zoo arima


【解决方案1】:

?Arima 页面说y(第一个参数)应该是一个ts 对象。我的猜测是对Arima 的第一次调用将您的zoo 对象强制为ts,但第二次调用不会。

解决此问题的一种简单方法是显式强制转换为ts

# Refit the old model with testData
new_model <- Arima(as.ts(testData.zoo), model = old_model)

【讨论】:

  • 哇,这就像一个魅力。谢谢 :) 我在 include.drift=FALSE 时尝试过我的代码,它运行良好,知道为什么当漂移设置为 TRUE 时会出现此错误吗?
  • @ganapathy: 不知道......也许是一个错误?
猜你喜欢
  • 1970-01-01
  • 2021-10-06
  • 2021-04-09
  • 2013-05-01
  • 2019-10-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-04
相关资源
最近更新 更多