我正在尝试为 ARIMA(p,0,q) 的所有组合生成拟合模型,例如,对于 p<=5 和 q<=5。
我的最终目标是根据 BIC、AIC 和 RMSE 等(使用精度计算)选择最佳模型。
使用循环方法,我能够获得所需的输出,
pdq_index_mat=expand.grid(0L:5L,0L,0L:5L)
# access the following link for the csv and run the following code to access the data for replication purposes for the following code/error
# https://drive.google.com/open?id=0ByLULem4QYiEcDB2OTJaejdVUkk
tsdf<-as.ts(read.csv(file.choose()))
#Loop method
ic_result_mat<-c()
reg<-c()
y<-tsdf[,"psoda"] #dependent variable of interest
for(i in 1:nrow(pdq_index_mat)){
# print(as.numeric(pdq_index_mat[i,])) serve as the c(p,0,q) to indicate which ARIMA of interest
reg<-arima(tsdf[,"psoda"],order=as.numeric(pdq_index_mat[i,]))
ic_result_mat<-rbind(ic_result_mat,c(BIC=BIC(reg),AIC=AIC(reg),accuracy(reg)[,c("RMSE","MAE","MPE","MAPE")]))
# uncomment the following line for the first error
# colnames(tsdf)[ncol(tsdf)+i]<-paste0("ARIMA(",paste0(pdq_index_mat[i,],collapse=","),")")
}
colnames(ic_result_mat)<-c("BIC","AIC","RMSE","MAE","MPE","MAPE")
rownames(ic_result_mat)<-paste0("ARIMA(",do.call(paste,c(pdq_index_mat[1:nrow(ic_result_mat),],sep=",")),")")
除了 1 个缺陷,我无法在循环内生成行名(例如,第一行的 ARIMA(0,0,0)),并提示以下错误:
Error in `rownames<-`(`*tmp*`, value = c(NA, NA, NA, NA, "ARIMA(1,0,0)" :
length of 'dimnames' [1] not equal to array extent
或者
Error in `rownames<-`(`*tmp*`, value = c("ARIMA(0)", "ARIMA(0)", "ARIMA(0)" :
attempt to set 'rownames' on an object with no dimensions
至于使用该apply()
方法,我什至无法获得回归列表
#List method
ic_result_mat<-c()
y<-tsdf[,"psoda"] #dependent variable of interest
reg_lst<-apply(pdq_index_mat,1,function(i)arima(y,order=as.integer(pdq_index_mat[i,])))
并提示以下错误:
Error in if (!is.numeric(order) || length(order) != 3L || any(order < :
missing value where TRUE/FALSE needed
对不起,不是专业的编码员。非常感谢专业人士的任何帮助。