原文:https://otexts.com/fppcn/backcasting.html
有时,“向后预测”一个时间序列是有用的 – 也就是说,对反向时间序列进行预测。虽然没有内置的R函数来实现这一点,但是这个过程很容易实现。以下函数对ts
对象和forecast
对象进行逆转。
# Function to reverse time
reverse_ts <- function(y)
{
ts(rev(y), start=tsp(y)[1L], frequency=frequency(y))
}
# Function to reverse a forecast
reverse_forecast <- function(object)
{
h <- length(object[["mean"]])
f <- frequency(object[["mean"]])
object[["x"]] <- reverse_ts(object[["x"]])
object[["mean"]] <- ts(rev(object[["mean"]]),
end=tsp(object[["x"]])[1L]-1/f, frequency=f)
object[["lower"]] <- object[["lower"]][h:1L,]
object[["upper"]] <- object[["upper"]][h:1L,]
return(object)
}
然后我们可以将这些函数应用到任一时间序列的向后预测中。这是一个应用于欧洲地区季度零售贸易数据的例子。数据来自1996-2011年。我们对1994-1995年的情况进行预测。
# Backcast example
euretail %>%
reverse_ts() %>%
auto.arima() %>%
forecast() %>%
reverse_forecast() -> bc
autoplot(bc) +
ggtitle(paste("Backcasts from",bc[["method"]])) +
xlab("时间") +
theme(text = element_text(family = "STHeiti"))
图 12.6: 对欧洲季度零售贸易数据使用 ARIMA 模型进行向后预测。