这是一种方法,对重叠位使用简单的线性回归来识别两个系列之间的关系,然后将该模型应用于ts1 的非重叠部分以估计ts2 的早期值。最后一步为您提供了一个新的ts 对象,该对象表示ts2 在非重叠期间的预测值。
# Make the toy data
set.seed(1)
ts1 <- ts(cumsum(rnorm(120,.1,1)), start = 1995, frequency = 12)
ts2 <- ts(cumsum(rnorm(120,.2,1)), start = 2004, frequency = 12)
# Now do the estimation
x <- as.vector(window(ts1, start = c(2004,1), end = c(2004,12)))
y <- as.vector(window(ts2, start = c(2004,1), end = c(2004,12)))
tsmod <- lm(y ~ x)
ts2preds <- predict(tsmod, newdata = as.data.frame(window(ts1, start = c(1995,1), end = c(2003,12))))
ts2prior <- ts(data = ts2preds, start = c(1995, 1), end = c(2003, 12), frequency = 12)
不过,如果您想自己回溯 ts2,Rob Hyndman 在他的 forecast 包中为您提供了 forecast() 函数。从他的博客关注an example:
library(forecast)
f <- frequency(ts2) # Identify the frequency of your ts
h <- (start(ts2)[1] - start(ts1)[1]) * f # Set the number of periods you want to backcast
revx <- ts(rev(ts2), frequency = f) # Reverse time in the series you want to backcast
ts2plus <- forecast(auto.arima(revx), h) # Do the backcasting
# Reverse its elements
ts2plus$mean <- ts(rev(ts2plus$mean), end=tsp(ts2)[1] - 1/f, frequency=f)
ts2plus$upper <- ts2plus$upper[h:1,]
ts2plus$lower <- ts2plus$lower[h:1,]
ts2plus$x <- ts2 # Replace the reversed reference series in the prediction object with the original one
# Plot it
plot(ts2plus, xlim=c(tsp(ts2)[1]-h/f, tsp(ts2)[2]))
这是产生的情节:
这两个系列的比较如下:
> cor(ts2plus$mean, ts2preds)
[1] 0.9760174
如果您的主要目标是获得这些早期值的最佳点预测,您可以考虑运行这两个版本并平均它们的结果。然后这变成了一个非常简单的多模型集合预测(或回溯)。