[問題] 寫loop選最適ARIMA model碰到的問題
[問題類型]:
程式諮詢
[軟體熟悉度]:
入門(寫過其他程式,只是對語法不熟悉)
[問題敘述]:
目前針對一筆3年的daily資料作建模(365*3筆daily count data),已利用過傳統
time-series建模方法,透過ACF, PACF等判斷去找model,也利用過auto.arima去找model
,現在希望透過手寫一個loop去run各種model的組合,再由最小AIC來選出較適的模型
當我run後,卻吐回一個error message給我,然後終止loop而沒有任何結果
"錯誤在stats:::arima(x, order = order, seasonal = seasonal, fixed =
par[1:narma], : wrong length for 'fixed' "
如果不用loop, 而是一個一個MODEL慢慢try,就可以跑(如下)
ex.
fit<-arimax(x,order=c(3,1,3),seasonal=list(order=c(0,1,1),period=7),xreg=xreg)
fit2<-arimax(x,order=c(3,1,3),seasonal=list(order=c(0,1,2),period=7),xreg=xreg)
..
..
[程式範例]:
count = 0
for(i in 0:5) {
for(j in 0:2) {
for(k in 0:1) {
for(l in 0:1) {
for(m in 0:2) {
for(n in 0:1) {
for(o in 0:2) {
model = arimax(ed0710$ED, order=c(i,j,k),
seasonal=list(order=c(l,m,n), period=7*o), xreg=xreg1)
if (count == 0) {
aicmin = model$aic
bestmodel = model
}
if ((count != 0)&& (model$aic< aicmin)) {
aicmin = model$aic
bestmodel = model
diff1 = j
diff2 = m
seas = o*7
}
count = count+1
}
}
}
}
}
}
print(bestmodel)
print(count)
print(diff1)
print(diff2)
print(seas)
}
[關鍵字]: time-series, ARIMA, loop
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 203.65.71.253
→
04/09 16:06, , 1F
04/09 16:06, 1F
→
04/09 16:25, , 2F
04/09 16:25, 2F
→
04/09 16:26, , 3F
04/09 16:26, 3F
→
04/09 16:26, , 4F
04/09 16:26, 4F
→
04/09 16:29, , 5F
04/09 16:29, 5F
→
04/09 16:30, , 6F
04/09 16:30, 6F
推
04/09 16:38, , 7F
04/09 16:38, 7F
→
04/10 07:05, , 8F
04/10 07:05, 8F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 2 篇):
R_Language 近期熱門文章
PTT數位生活區 即時熱門文章