簡體   English   中英

使用Fourier進行xreg和newxreg的分層時間序列預測

[英]Hierarchical time series prediction using Fourier for xreg and newxreg

我想在分層時間序列中使用xreg = Fourier(ts,k,f)作為回歸變量。

我可以讓回歸器為單個系列工作。

我有一個分層的時間序列hts,它由與第一個相似的序列組成(時間步數相同)。

hts參考: https ://robjhyndman.com/publications/hierarchical-tourism/

我在使用相同回歸器的hts預測中得到錯誤。 問題是什么?

train_ts:整個hts,格式為隔夜。
top_ts:僅是頂級時間序列

當完成一個系列時,使用xreg和newxreg的top_ts可以工作。

KK <- 12
REG= fourier(top_ts,KK,52)

model <- auto.arima(top_ts, xreg=fourier(top_ts, K=KK))
fcstResult <- forecast(model, h=1, xreg= REG, newxreg=REG)

作品

當我預測類似於隔夜的hts時,train_ts,

train_ts <- window(vis_ts, c(2,1), end= c(3, 52))

fcstResult <- forecast(train_ts, h=1, fmethod="arima", method = "bu")

作品

當我在hts上使用相同的回歸XREG時,它會出錯:

fcstResult <- forecast(
  train_ts, h = 1, method = "bu", fmethod = "arima", xreg=REG, newxreg=REG)

OR

fcstResult <- forecast(
  train_ts, h = 1, method = "bu", fmethod = "arima", xreg=REG, newxreg=REG, lambda=0)



Error in model.frame.default(formula = x ~ xregg, drop.unused.levels = TRUE) :
  variable lengths differ (found for 'xregg')

(我將所有列都設為非零並添加了一個小的隨機噪聲,所以這不是問題)

在您的第一個代碼塊中, newxreg參數將被忽略, h參數也將被忽略。 REG的值被認為是將來時間段所需的回歸值。 如果您的訓練數據的長度等於52的倍數,由於傅立葉項的周期性,這恰好是正確的,但是最好像這樣明確:

library(hts)
vis_ts <- hts(fpp2::visnights, characters = c(3, 5))
train_ts <- window(vis_ts, end=c(2010,4))
test_ts <- window(vis_ts, start=c(2011,1))
train_top <- aggts(train_ts, level=0)
test_top <- aggts(test_ts, level=0)
train_reg <- fourier(train_top, K=2)
test_reg <- fourier(test_top, K=2)

model <- auto.arima(train_top, xreg=train_reg)
fcstResult <- forecast(model, xreg=test_reg)

使用分層方法時,需要同時對應於訓練和測試時間段傳遞xregnewxreg參數。 在此函數中,將檢查newxreg的行以確保它們與h的值匹配。 這導致錯誤。

以下代碼將起作用

fcast_hts <- forecast(train_ts, method='bu', fmethod='arima', 
  xreg=train_reg, newxreg=test_reg)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM