使用apply()为ARIMA生成所有子集回归

使用apply()为ARIMA生成所有子集回归,r,arima,R,Arima,我正在尝试为ARIMA(p,0,q)的所有组合生成拟合模型,比如说,对于pIs,为什么您不只是使用forecast::auto.ARIMA?请使其可复制,以便我们可以查看您的错误来源。访问csv的以下链接…此链接在哪里?对不起,我的错,我在中添加了csv文件链接@谢谢你的建议,我试过用过一次,但可能是因为我的电脑性能,速度很慢。但在我第二次重试时,它变为ok。尽管如此,我还是希望找到使用apply和loop的方法,将其作为像我这样的新手的一种实践。无论如何,再次感谢你的建议 pdq_index_

我正在尝试为ARIMA(p,0,q)的所有组合生成拟合模型,比如说,对于pIs,为什么您不只是使用
forecast::auto.ARIMA
?请使其可复制,以便我们可以查看您的错误来源。访问csv的以下链接…此链接在哪里?对不起,我的错,我在中添加了csv文件链接@谢谢你的建议,我试过用过一次,但可能是因为我的电脑性能,速度很慢。但在我第二次重试时,它变为ok。尽管如此,我还是希望找到使用apply和loop的方法,将其作为像我这样的新手的一种实践。无论如何,再次感谢你的建议
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=",")),")")
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
#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