Backcasting in R

Sometimes it is useful to “backcast” a time series — that is, forecast in reverse time. Although there are no in-built R functions to do this, it is very easy to implement. Suppose x is our time series and we want to backcast for $h$ periods. Here is some code that should work for most univariate time series. The example is non-seasonal, but the code will also work with seasonal data.

library(forecast)
x <- WWWusage
h <- 20
f <- frequency(x)
# Reverse time
revx <- ts(rev(x), frequency=f)
# Forecast
fc <- forecast(auto.arima(revx), h)
plot(fc)
# Reverse time again
fc$mean <- ts(rev(fc$mean),end=tsp(x)[1] - 1/f, frequency=f)
fc$upper <- fc$upper[h:1,]
fc$lower <- fc$lower[h:1,]
fc$x <- x
# Plot result
plot(fc, xlim=c(tsp(x)[1]-h/f, tsp(x)[2]))

Rplot


Related Posts:


  • Thanks for sharing this. I did backasting on my undergrad research, but I use loops.

  • Econstudent

    Professor, is there any theory on this kind of models? Any references would be helpful! Thank you!

    • Look for papers on time reversibility: http://goo.gl/yaSoev.
      Also Tong (1990), Section 4.4: http://amzn.com/0198523009/?tag=prorobjhyn-20

      • Econstudent

        Thank you, Professor. Loosely speaking, the literature shows that the time reversibility applies to only Gaussian time series. What is your view on that? Do you think the fact that most time series are unlikely Gaussian means backcasting using, say, ARMA model, is not justified theoretically?

        • The Gaussian linear assumption is an approximation. It is rarely true, but it is not far from the truth in many situations. Short-term backcasting with ARIMA models works about as well as short-term forecasting with ARIMA models.

  • liam

    Hi Rob
    I’m trying to complete a similar backcasting exercise to this, but rather than fitting a new model to the reversed data, I wish to use the existing ARIMAX model I’ve fitted to the ordinary forward data with the first year chopped off, then try to backcast the chopped off first year using the fitted model.
    Any suggestions?
    Cheers

  • Katie Cuko

    Hello Prof. Rob. I would like to thank you, first of all, for your very useful info on forecasting. Second, I would like to ask a question on backcasting. The above plot has a sentence “sometimes it’s useful to backcast a time series”. Would you please point me to the right direction, as to when would be such a scenario. I am interested in business applications…there are a lot of papers on the subject but they all kind of state that backcasting is a planning technique if you have a future in mind you go back. Any help on the subject would be much appreciated. Thank you!

    • Seasonal adjustment processes often involve a backcasting step to extend the series and allow moving average trend estimation at the beginning of the series.

  • ChristyA

    Hi Professor. Thank you for your example! I was wondering, can this approach be done with ets() instead of auto.arima()? When I try to do so, I run into errors that I cannot seem to work around.

    • Replacing `auto.arima` with `ets` works for me. (forecast v8.0)