In a recent online course on macroeconomic forecasting, there was an excercise to model
y(t) = 3.0 + 0.55 y(t-1) + e(t)
where e(t)
is defined as
et <- c(-1.2138662, -0.2854597, 0.5902700, 0.8285463, -0.9954260, -0.3716332)
Now I tried to do this in R (the course used EViews), however I do not come to the solution given there: 5.648 for the 5th element. I tried (similar to this blogpost):
y <- rep(NA,6)
y[1] <- 0
y[2] <- 3 + 0.55*y[1]+et[1]
y[3] <- 3 + 0.55*y[2]+et[2]
y[4] <- 3 + 0.55*y[3]+et[3]
y[5] <- 3 + 0.55*y[4]+et[4]
y[6] <- 3 + 0.55*y[5]+et[5]
and then
y <- rep(NA,6)
y[1] <- et[1]
y[2] <- 3 + 0.55*y[1]+et[2]
y[3] <- 3 + 0.55*y[2]+et[3]
y[4] <- 3 + 0.55*y[3]+et[4]
y[5] <- 3 + 0.55*y[4]+et[5]
y[6] <- 3 + 0.55*y[5]+et[6]
and then
arima.sim(list(order=c(1,0,0), ar=0.55), n=6, innov=head(et,6)+3)
However all three methods give different results. I wonder why this is, I am afraid I did not understand something basic.
arima.sim
has a "burn-in" period in order to reach stationarity. Argumentn.start
sets the length of this period, and it must has lengthar
+ma
. For anAR(1)
process,n.start
must be at least 1. Note, if you don't specifyn.start
,arima.sim
will automatically compute a reasonable one for you.Given
n.start
(either a specified one or auto-computed one),arima.sim
then randomly samplen.start
innovations for "burn-in". It is right because of this random procedure, you will get different result from one run to another:We can eliminate such randomness, by providing a set of starting innovations using
start.innov
argument. Note, this vector must has lengthn.start
:Now, compare this last
arima.sim
with the following:We have everything completely reproducible.
The above generates zero-mean time series; if you want mean at 3, shift the result by
+3
yourself: