# In this program we are going to use the function "ts.sim" to simulate 200 observations of # some simple AR models, plot them and then plot their sample ACF's and sample PACF's. # Note that, due to sampling variation, the sample ACF's and sample PACF's will not exactly # coincide with their theoretical (population) ACF's and PACF's even though this would be # the case as the sample size goes to infinity. The purpose here is to show the white noise, # AR(0) model, the AR(1) model with positive autocorrelation (ar=0.7) and the AR(1) model # with negative autocorrelation. # Here we simulate an AR(1) model with ar1 = 0.0. # Notice the lack of autocorrelation at any lag. # The reversion to the mean is, in essence, immediate. ts.sim.1<-arima.sim(list(order=c(1,0,1), ar=0.0, ma=0.0), n=200) ts.plot(ts.sim.1) windows() par(mfrow=c(1,2)) acf(ts.sim.1) pacf(ts.sim.1) # Here we simulate a AR(1) model with ar1 = 0.7. # Notice the autocorrelation being positive. # The series reverts to the mean but slowly. ts.sim.2<-arima.sim(list(order=c(1,0,1), ar=0.7, ma=0.0), n=200) windows() par(mfrow=c(1,1)) ts.plot(ts.sim.2) windows() par(mfrow=c(1,2)) acf(ts.sim.2) pacf(ts.sim.2) # Here we simulate an AR(1) model with ar1 = -0.7. # Notice the autocorrelation being negative for lag 1 # and positive for lag 2, continuing to switch back and # forth across the mean though exhititing mean reversion. # This is a time series with a "saw-tooth" pattern. ts.sim.3<-arima.sim(list(order=c(1,0,1), ar=-0.7, ma=0.0), n=200) windows() par(mfrow=c(1,1)) ts.plot(ts.sim.3) windows() par(mfrow=c(1,2)) acf(ts.sim.3) pacf(ts.sim.3)