【问题标题】:Can time series analysis forecast the past?时间序列分析可以预测过去吗?
【发布时间】:2021-12-15 23:53:05
【问题描述】:

我正在尝试使用时间序列分析来猜测过去的数据。 通常,时间序列分析预测未来,但反之,时间序列可以预测(?)过去吗?

我这样做的原因是,过去的数据中缺少部分。 我正在尝试用 R 或 Python 写下代码。

我在 R 中尝试了 forecast(arima, h=-92)。这没有用。 这是我在 R 中尝试过的代码。

library('ggfortify')
library('data.table')
library('ggplot2')
library('forecast')
library('tseries')
library('urca')
library('dplyr')
library('TSstudio')
library("xts")

df<- read.csv('https://drive.google.com/file/d/1Dt2ZLOCASYIbvviWQkwwgdo2BdmKfl9H/view?usp=sharing')
colnames(df)<-c("date", "production")
df$date<-as.Date(df$date, format="%Y-%m-%d")

CandyXTS<- xts(df[-1], df[[1]])
CandyTS<- ts(df$production, start=c(1972,1),end=c(2017,8), frequency=12 )


ggAcf(CandyTS)

forecast(CandyTS, h=-92)

【问题讨论】:

  • 也许倒转时间序列并定期预测未来......?
  • 请提供足够的代码,以便其他人更好地理解或重现问题。
  • 刚刚添加了R代码。
  • Sotos/好主意。我不确定这是否可以。
  • 您是在编写代码以实现目标时寻求帮助,还是从概念的角度来看是否可以?

标签: python r time-series


【解决方案1】:

这是可能的。它被称为回溯。您可以在预测:原理与实践的this chapter 中找到一些信息。

基本上你需要反向预测。我根据本章中的代码和您的数据添加了一个示例。根据需要进行调整。您创建一个反向索引并使用它来及时回溯。您可以使用与 ETS 不同的模型。同理

# I downloaded data.
df1 <- readr::read_csv("datasets/candy_production.csv")
colnames(df1) <- c("date", "production")

library(fpp3)
back_cast <- df1 %>% 
  as_tsibble() %>% 
  mutate(reverse_time = rev(row_number())) %>%
  update_tsibble(index = reverse_time) %>% 
  model(ets = ETS(production ~ season(period = 12))) %>%
  # backcast
  forecast(h = 12) %>%
  # add dates in reverse order to the forecast with the same name as in original dataset. 
  mutate(date = df1$date[1] %m-% months(1:12)) %>%
  as_fable(index = date, response = "production",
           distribution = "production")

back_cast %>%
  autoplot(df1) +
  labs(title = "Backcast of candy production",
       y = "production")

【讨论】:

  • 你真是个天才。非常感谢!
猜你喜欢
  • 2021-06-12
  • 2023-04-02
  • 2019-12-15
  • 2013-06-02
  • 2019-05-21
  • 2021-12-21
  • 2017-12-07
  • 2017-11-24
  • 2021-04-07
相关资源
最近更新 更多