【问题标题】:R package "forecast": Daily data with weekly frequencies lead to wrong annual figuresR包“预测”:每周频率的每日数据导致错误的年度数据
【发布时间】:2019-09-25 02:08:16
【问题描述】:

我正在尝试将 ETS 和 ARIMA 模型拟合到 2017 年 1 月 1 日至 2019 年 3 月 31 日的每日销售数据

使用 R 包“预测”,我从我的数据中创建了一个 ts 对象。在这里,我使用了频率7。不幸的是,这改变了我的日期符号,如下所示,每第 7 个周期开始一个新的“年”,而不是保持旧的日期格式。

问题:如何从我的数据中应用每周季节性,同时保持所需的日期结构为“年-月-日”格式 (2017-01-01)。

DF <- read_excel("....",
                 col_names = TRUE,
                 col_types = c("date", "numeric", "numeric", 
                               "numeric", "numeric","numeric","numeric"))
TS <- ts(DF[,2:6], , start = c(2017, 1), frequency = 7)
TS_ggseasonplot <- lapply(TS,function(x){ggseasonplot(x, polar=TRUE)})


应用 ts 之前的旧输出。

Date       V_1
   <date>       <dbl>
 1 2017-01-01       0
 2 2017-01-02     529
 3 2017-01-03     556
 4 2017-01-04     544
 5 2017-01-05     510
 6 2017-01-06     319
 7 2017-01-07       0
 8 2017-01-08       0
 9 2017-01-09    1296
10 2017-01-10     388

之后:

Date         V_1    
2017.000       0      
2017.286     556   
2017.429     544    
2017.571     510    
2017.714     319      
2017.857       0      
2018.000       0      
2018.143    1296    

【问题讨论】:

    标签: r arima forecast


    【解决方案1】:

    这是使用 ts 对象进行预测的一大缺点,也是我们开发新包以直接处理时间序列数据帧(tsibble 对象)的一大动力。

    对于预测包,您可以使用 lubridate 包的lubridate::date_decimal() 函数将十进制日期转换回日期。

    lubridate::date_decimal(2017.3287671233)
    #> [1] "2017-05-01 00:00:00 UTC"
    

    reprex package (v0.2.1) 于 2019-05-15 创建

    【讨论】:

      猜你喜欢
      • 2018-02-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-03
      • 1970-01-01
      • 2021-02-08
      • 1970-01-01
      • 2022-09-23
      • 1970-01-01
      相关资源
      最近更新 更多