【问题标题】:In R, can the original time series impact forecast results for a subset time series?在 R 中,原始时间序列会影响子时间序列的预测结果吗?
【发布时间】:2018-08-13 14:45:48
【问题描述】:

我使用下面的代码在 R 中对时间序列数据子集的 stl 进行了预测。场景 1 和 2 的唯一区别是,我在场景 2 中错误地将原始时间序列和子时间序列都设置为 start=c(2015,12)。两种场景的预测结果不同。对于预测中使用的子集数据,两种方案的开始日期相同。我不明白为什么原始时间序列开始日期会影响预测结果。

# Scenario 1    

ts.vision = ts(data=vision$ADJ_ILR, frequency = 12,start=c(2015,1), end=c(2017,12))                             
ts.vision.sub <- window(ts.vision, start=c(2015, 12))                               
ts.vision.fit <- stl(ts.vision.sub, t.window=15, s.window="periodic", robust=TRUE)                              
forecast(ts.vision.fit, h=12)


# Scenario 2    

ts.vision = ts(data=vision$ADJ_ILR, frequency = 12,start=c(2015,12), end=c(2017,12))                                
ts.vision.sub <- window(ts.vision, start=c(2015, 12))                               
ts.vision.fit <- stl(ts.vision.sub, t.window=15, s.window="periodic", robust=TRUE)                              
forecast(ts.vision.fit, h=12)   

这是一个类似的情况,我使用 base R 上可用的 nottem 数据集重写了两个场景: # 场景一 ts.nottem = ts(nottem, 频率 = 12,start=c(1920,1), end=c(1939,12)) ts.nottem.sub

#Scenario 2
ts.nottem = ts(nottem, frequency = 12,start=c(1937,12), end=c(1939,12))
ts.nottem.sub <- window(ts.nottem, start=c(1937, 12))   
ts.nottem.fit <- stl(ts.nottem.sub, t.window=15, s.window="periodic", robust=TRUE)      
forecast(ts.nottem.fit, h=12)

我不明白为什么场景 1 和 2 的子集时间序列数据相同,但预测结果却不同。

【问题讨论】:

  • 您可能想为该问题提供一些上下文。这是指哪种技术/环境?
  • 您能否使用基础 R 中可用的数据集之一(例如 nottem)来复制这个问题?用一个可重复的最小例子更容易回答。
  • 这里是场景 1 和 2 重写以使用基础 R 中可用的 nottem 数据集。

标签: r forecasting


【解决方案1】:

这是您的示例,其中包含一些内置数据

library(forecast)
ts.1 <- ts(data=nottem[1:36], frequency = 12, start=c(2015,1), end=c(2017,12))                             
ts.1.sub <- window(ts.1, start=c(2015, 12))                               
ts.1.fit <- stl(ts.1.sub, t.window=15, s.window="periodic", robust=TRUE)                              
ts.1.fc <- forecast(ts.1.fit, h=12)

ts.2 <- ts(data=nottem[1:36], frequency = 12, start=c(2015,12), end=c(2017,12))                             
ts.2.sub <- window(ts.2, start=c(2015, 12))                               
ts.2.fit <- stl(ts.2.sub, t.window=15, s.window="periodic", robust=TRUE)                              
ts.2.fc <- forecast(ts.2.fit, h=12)

#all.equal(ts.1.fc, ts.2.fc) # NO!

我省略了长的愤怒信息!发生了什么?看一下两个子集对象:

head(ts.1.sub)
#>       Jan  Feb  Mar  Apr  May Jun Jul Aug Sep Oct Nov  Dec
#> 2015                                                  39.8
#> 2016 44.2 39.8 45.1 47.0 54.1

head(ts.2.sub)

#>       Jan  Feb  Mar  Apr  May Jun Jul Aug Sep Oct Nov  Dec
#> 2015                                                  40.6
#> 2016 40.8 44.4 46.7 54.1 58.5

它们不一样,因为在场景 1 中,您将获得原始数据中的第 12 到第 36 个值,而在场景 2 中,您将获得第 1 到第 25 个值。

【讨论】:

    猜你喜欢
    • 2018-10-02
    • 1970-01-01
    • 2015-05-19
    • 2021-11-28
    • 2013-10-04
    • 2019-09-06
    • 2013-09-26
    • 2014-04-03
    • 1970-01-01
    相关资源
    最近更新 更多