[英]Can time series analysis forecast the past?
我试图通过使用时间序列分析来猜测过去的数据。 通常,时间序列分析预测未来,但在相反的方向,时间序列可以预测(?)过去吗?
我这样做的原因是,过去的数据中缺少部分。 我正在尝试用 R 或 Python 写下代码。
我在 R 中尝试了 predict(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)
有可能的。 它被称为倒推。 您可以在“预测:原则与实践”的这一章中找到一些信息。
基本上你需要反向预测。 我根据本章中的代码和您的数据添加了一个示例。 根据需要进行调整。 您创建一个反向索引并使用它来及时回溯。 您可以使用与 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")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.