# 2.2 Moving Averages and Autoregressive Processes # Plot 2.2.1a: Autocorrelation functions of AR(1)-processes with different values of a. k <- 0:20 a1 <- -0.7 a2 <- 0.5 a3 <- 0.9 plot(k,a1^k,type="b",ylab="rho") lines(k,a2^k,type="b",lty=2) lines(k,a3^k,type="b",lty=3) # Plot 2.2.2a: Realizations AR(1) for a1=0.5 and a2=1.5. t <- 0:10 a1 <- 0.5 a2 <- 1.5 Y1 <- Y2 <- rep(0,length(t)) for(i in 2:length(t)) { Y1[i] <- a1*Y1[i-1] + rnorm(1) Y2[i] <- a2*Y2[i-1] + rnorm(1) } plot(range(t),range(c(Y1,Y2)),type="n",xlab="time",ylab="Y") lines(t,Y1,type="b") lines(t,Y2,type="b",col=2) # Plot 2.2.3a: Realization of the AR(2)-process with a1=0.6, a2=-0.3. t <- 0:201 a1 <- 0.6 a2 <- -0.3 Y <- rep(0,length(t)) for(i in 3:length(t)) { Y[i] <- a1*Y[i-1] + a2*Y[i-2]+ rnorm(1) } plot(t[-1],Y[-1],type="b",xlab="time",ylab="Y") # Plot 2.2.4a: Empirical partial autocorrelation function of the AR(2)-data in Plot 2.2.3a pacf(Y[-1])