【问题标题】:Hierarchical forecasting with user-defined function in R, arima with fourier terms在 R 中使用用户定义的函数进行分层预测,使用傅里叶项的 arima
【发布时间】:2019-02-11 12:52:14
【问题描述】:

我正在尝试一种自上而下的方法来预测零售店产品的需求。

fourier_forecasts = forecast(sales_weekly_hts, h=12,method="tdfp", FUN=function(x) auto.arima(x, xreg=fourier(x, K=12), seasonal=FALSE))

sales_weekly_hts 是一个 hts 对象,其中包含 2.5 年的每周销售数据。

它给了我错误:-

“预测错误。Arima(models, h = h) : 未提供回归量”

我猜这个错误是因为它无法获得样本外预测的傅里叶项,但我不知道如何解决这个问题。 难道不知道要预测未来多少个周期吗?

最小可重现示例:-

library(dplyr)
library(hts)

# creating a time series matrix containing 4 series and 133 weeks random data 
min_rep_eg = matrix(data = rnorm(n = 133*4 ,mean = 2), nrow = 133, ncol = 4) %>% ts(frequency = 365.25/7)

# giving names to the 5 time series. These names are used to create the hierarchy.
colnames(min_rep_eg) = c("10011001","10011003","10031021","10031031")

# creating the hts.
min_rep_eg_hts = hts(min_rep_eg, characters = c(4, 4))

min_rep_eg_hts_fc = forecast(min_rep_eg_hts, h=2,method="tdfp", FUN=function(x) auto.arima(x, xreg=fourier(x, K=12), seasonal=FALSE))

【问题讨论】:

  • 嗨,请provide data,例如将dput(<myData>) 或dput(head(<myData>)) 的输出添加到您的问题中。您将有更好的机会获得出色的答案!
  • 也许尝试考虑更少的傅立叶项(即减少K)?较低的K 意味着您的季节性模式的复杂性较低。通过减少K,您可以减少模型用来近似季节性模式的正弦和余弦对的频率。
  • 此外,检查每周预测您的销售数据是否有意义可能是值得的 - 也许每月汇总会减少噪音?
  • @jay.sf dput 给了我大量的输出,无法粘贴到这里。我会尝试写更多关于数据的内容。
  • 添加了一个最小可重现示例

标签: r forecasting arima


【解决方案1】:

我现在才看到你的帖子。当您使用 auto.arima 函数时,解决问题的最简单方法是通过 fmethod 参数使用 arima 模型。然后,通过xreg 和newxreg 设置外部回归器的值。

以您的可重现示例:

library(dplyr)
library(hts)

# creating a time series matrix containing 4 series and 133 weeks random data 
min_rep_eg = matrix(data = rnorm(n = 133*4 ,mean = 2), nrow = 133, ncol = 4) %>% ts(frequency = 365.25/7)

# giving names to the 5 time series. These names are used to create the hierarchy.
colnames(min_rep_eg) = c("10011001","10011003","10031021","10031031")



# creating the hts.
min_rep_eg_hts = hts(min_rep_eg, characters = c(4, 4))
x=allts(min_rep_eg_hts)[,1]



min_rep_eg_hts_fc = forecast(min_rep_eg_hts, h=1,method="tdfp", fmethod ="arima",xreg=fourier(x, K=12),newxreg=tail(fourier(x, K=12),1))

输出:

【讨论】:

    猜你喜欢
    • 2020-01-14
    • 2012-05-18
    • 1970-01-01
    • 2011-05-27
    • 2014-07-06
    • 2017-06-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多