#========================================================== # Simulation of an AR(1) Model using arima.sim() # Code is from p 67 of Z&W (slightly modified) # Also illustrates par(mfrow(2,2)) and graph labeling #======================================================= #The simulation, using set.seed(101) and start.innov burn-in set.seed(101) e<-rnorm(100,sd=1) e.start=rnorm(25, sd=1) y.ar1<- 1+arima.sim(model=list(ar=0.75), n=100,innov=e, start.innov=e.start) # check on the mean mean(y.ar1) #Three pictures in one: # #(1) the simulated series, #(2) the theoretical ACF #(3) the empirical ACF for our simulation par(mfrow=c(2,2)) tsplot(y.ar1, main="Simulated AR(1)") abline(h=1) gamma.j<-rep(.75,10)^seq(10) tsplot(gamma.j, type="h", main="Theoretical ACF for AR(1)", ylab="Autocorreleation", xlab="Lag") temp<-acf(y.ar1, lag.max=10, plot=F) tsplot(temp$acf,type="h", main="Empirical ACF for Simulated AR(1)", ylab="Autocorreleation", xlab="Lag") #One line to make it prettier: abline(h=0)