【问题标题】:Hierarchical time series prediction using Fourier for xreg and newxreg使用傅里叶对 xreg 和 newxreg 进行分层时间序列预测
【发布时间】:2020-01-14 22:44:43
【问题描述】:

我想在分层时间序列中使用 xreg = Fourier(ts, k,f) 作为回归量。

我可以让回归器为单个系列工作。

我有一个分层时间序列 hts,它由与第一个相似的序列组成(时间步数相同)。

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

我在使用相同回归量的 hts 的预测中出现错误。有什么问题?

train_ts:整个 hts,形式为 visnights。
top_ts :只是顶级时间序列

当为单个系列完成时, top_ts ,使用 xreg 和 newxreg 可以工作。

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)

作品

当我对类似于 visnights、train_ts 的 hts 进行预测时,

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')

(我将所有列设为非零并添加了一个小的随机噪声,所以这不是问题)

【问题讨论】:

  • Per r 标签(悬停查看):请提供最小且可重现的示例以及所需的输出。对数据使用dput(),并使用library() 调用指定所有非基础包。

标签: r regression fft hierarchical-data arima


【解决方案1】:

在您的第一个代码块中,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)

使用分层方法时,xreg 和 newxreg 参数都需要与训练和测试周期相对应地传递。在此函数中,检查newxreg 的行以确保它们与h 的值匹配。这会导致错误。

以下代码将起作用

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

【讨论】:

    猜你喜欢
    • 2011-05-27
    • 2015-07-14
    • 2015-04-05
    • 1970-01-01
    • 2012-05-18
    • 2021-08-17
    • 2014-04-18
    • 2021-10-25
    • 1970-01-01
    相关资源
    最近更新 更多