我正在學習創建具有多個季節性的時間序列的預測模型。以下是我所指的數據集的子集。此數據集包括小時數據點,我希望在我的arima模型中包含每日和每週季節性。以下是數據集的子集:R的多個季節性的arima模型
data= c(4,4,1,2,6,21,105,257,291,172,72,10,35,42,77,72,133,192,122,59,29,25,24,5,7,3,3,0,7,15,91,230,284,147,67,53,54,55,63,73,114,154,137,57,27,31,25,11,4,4,4,2,7,18,68,218,251,131,71,43,55,62,63,80,120,144,107,42,27,11,10,16,8,10,7,1,4,3,12,17,58,59,68,76,91,95,89,115,107,107,41,40,25,18,14,15,6,12,2,4,1,6,9,14,43,67,67,94,100,129,126,122,132,118,68,26,19,12,9,5,4,2,5,1,3,16,89,233,304,174,53,55,53,52,59,92,117,214,139,73,37,28,15,11,8,1,2,5,4,22,103,258,317,163,58,29,37,46,54,62,95,197,152,58,32,30,17,9,8,1,3,1,3,16,109,245,302,156,53,34,47,46,54,65,102,155,116,51,30,24,17,10,7,4,8,0,11,0,2,225,282,141,4,87,44,60,52,74,135,157,113,57,44,26,29,17,8,7,4,4,2,10,57,125,182,100,33,27,41,39,35,50,69,92,66,30,11,10,11,9,6,5,10,4,1,7,9,17,24,21,29,28,48,38,30,21,26,25,35,10,9,4,4,4,3,5,4,4,4,3,5,10,16,28,47,63,40,49,28,22,18,27,18,10,5,8,7,3,2,2,4,1,4,19,59,167,235,130,57,45,46,42,40,49,64,96,54,27,17,18,15,7,6,2,3,1,2,21,88,187,253,130,77,47,49,48,53,77,109,147,109,45,41,35,16,13)
我試圖使用的代碼如下:
tsdata = ts (data, frequency = 24)
aicvalstemp = NULL
aicvals= NULL
for (i in 1:5) {
for (j in 1:5) {
xreg1 = fourier(tsdata,i,24)
xreg2 = fourier(tsdata,j,168)
xregs = cbind(xreg1,xreg2)
armodel = auto.arima(bike_TS_west, xreg = xregs)
aicvalstemp = cbind(i,j,armodel$aic)
aicvals = rbind(aicvals,aicvalstemp)
}
}
因爲xreg1和xreg2行數是在上面的命令的cbind命令失敗不同。我甚至嘗試在傅立葉函數中使用1:length(data)參數,但這也給我一個錯誤。如果有人能夠糾正上述代碼中的錯誤,以使用AIC值最小的arima模型預測未來24小時,這將非常有幫助。另外,如果您可以通過創建培訓和測試數據集在代碼中包含數據分割,那將非常棒。謝謝你的幫助。
當'i = 1'和'j = 1'時,您的對象'aicvals'還不存在。這可能會在最後一行的'rbind'中產生一些問題。也許你需要這樣的東西:'if(i == 1&j == 1)aicvals <-aicvalstemp else aicvals < - rbind(aicvals,aicvalstemp)'。 – GPierre
@GPierre我開始時嘗試初始化它們的值爲NULL,但它仍然不起作用。請參閱編輯的代碼。 –