# Prediction of time series using AR(1) on the difference of the time series in R

I have a time series (quarterly data) that I will use to predict the upcoming 4 quarters.The total number of observations is 20 quarters, thus, I need to predict quarter 21 -> 24. First I took the diff(data) to have a stationary data and I want to fit AR(1). I am using the following in R:

arima(diff(data), order=c(1,0,0)) and I obtained: ar1 (- 0.2441) and Intercept (1.2004)

Is the following correct?

∆y(t+1) = 1.2004 - 0.2441*∆y(t)

∆y(t+2) = 1.2004 - 0.2441*∆y(t+1)


If I want to predict y(t+1), do I find ∆y(t+1) and then

y(t+1) = y(t) + ∆y(t+1)

y(t+2) = y(t) + ∆y(t+1)+ ∆y(t+2)


and so on... until y(t+4)

Is this analogy correct? Do you know how can I get the predicted value in R without doing it manually? How can I tell R that first I need to predict the delta and then the original value.

The answer by Gennaro Tedesco gives the forecasts for the differenced data. If you need forecasts for the original data, you may use

predict( arima(data,order=c(1,1,0)), n.ahead=4 )


where the order argument being c(1,1,0) rather than c(1,0,0) reflects that you want to fit an AR(1) model to differenced rather than original data. In other words, specifying the middle number in the order argument to be 1 rather than 0 does the differencing for you.

Regarding why you cannot obtain the same results manually as obtained by arima, perhaps the problem is the following. "Intercept" in the output of an ARIMA model in R may be a little misleading. That is, an AR(1) with "intercept" equal to $\mu$ means (in R)

$$(x_t-\mu) = \varphi (x_{t-1}-\mu) + \varepsilon_t$$

rather than

$$x_t = \mu + \varphi x_{t-1} + \varepsilon_t.$$

The latter part of my answer is based on this post, see especially ISSUE 1. Meanwhile, ISSUE 2 is very relevant to the former part of my answer.

forecast(model, h=4)

predict (model, n.ahead=4)