# In this program we are going to use some R prgramming statements to simulate 200
# observations of,first, a white noise time series, i.e. an AR(1) model with
# ar1 = 0.0, then a stationary AR(1) model with ar1 = 0.7, then a Random Walk
# AR(1) model with ar1 = 1.0, and , finally, an explosive AR(1) model with
# ar1 = 1.01.
# If you want to see the different "shapes" of the time series in these cases,
# just delete the graphs after each run and run the program again and again and again.
# Here we simulate an AR(1) model with ar1 = 0.0 (white noise)
Y1<-rnorm(200,0,1)
par(mfrow=c(1,2))
plot.ts(Y1)
acf(Y1)
windows()
# Here we simulate an AR(1) model with ar1 = 0.7.
Z<-rnorm(200,0,1)
Y2<-numeric(200)
Y2[1]<-Z[1]
for (i in 2:200) Y2[i]<-0.7*Y2[i-1] + Z[i]
par(mfrow=c(1,2))
plot.ts(Y2)
acf(Y2)
windows()
# Here we simulate an AR(1) model with ar1 = 1.0.
# The "Unit Root" case
Z<-rnorm(500,0,0.5)
Y3<-numeric(500)
Y3[1]<-Z[1]
for (i in 2:500) Y3[i]<-1.0*Y3[i-1] + Z[i]
par(mfrow=c(1,2))
plot.ts(Y3)
acf(Y3)
windows()
# Here we simulate an AR(1) model with ar1 = 1.01
# The "Explosive" case
Z<-rnorm(500,0,0.5)
Y4<-numeric(500)
Y4[1]<-Z[1]
for (i in 2:500) Y4[i]<-1.01*Y4[i-1] + Z[i]
par(mfrow=c(1,2))
plot.ts(Y4)
acf(Y4)