install.packages("astsa")

library("astsa")

### 2 a)

num_2a = arima.sim(model=list(ar=0.7), n=300)
acf(num_2a)

### 2 b)

k = 1:20
n = 300
phi = 0.7
w_kk = (1-phi^(2*k))*(1+phi^2)/(1-phi^2) - 2*k*phi^(2*k)
variance = w_kk/n
acf(num_2a)
points(k, phi^k, col='red')
lines(k, phi^k-1.96*sqrt(variance), col='red', lty=2)
lines(k, phi^k+1.96*sqrt(variance), col='red', lty=2)

The expectations of AR(1) process, represented by red dots, lie inside the red bands, but the ones before lag 5 falls outside the blue bands. Since the expectation follows pretty closely with the ACF plots, AR(1) model with phi=0.7 is better fit than white noise.