I have fitted the ARIMA models to the original time series, and the best model is ARIMA(1,1,0). Now I want to simulate the series from that model. I wrote the simple AR(1) model, but I couldn't understand how to adjust the difference within the model ARI(1,1,0).
The following R code for AR(1) series is:
phi= -0.7048
z=rep(0,100)
e=rnorm(n=100,0,0.345)
cons=2.1
z[1]=4.1
for (i in 2:100) z[i]=cons+phi*z[i-1]+e[i]
plot(ts(Y))
How do i include the difference term ARI(1,1) in above code.
Any one help me in this regard.
Best Answer
If you want to simulate ARIMA you can use
arima.sim
in R, there is no need to do it by hand. This will generate the series you want.You can look at the code of how this is achieved by typing
arima.sim
in R command line. Alternatively if you do it yourself, the function you are probably looking isdiffinv
. It computes the inverse of lagged differences.For recursive sequences
R
has a nice functionfilter
. So instead of using loopyou can write
This will give the identical result to
arima.sim
example above: