Consider the stochastic process AR (1). Generate a sequence of random variables 500 and assuming c = 3 and phi = {0.5, 0.95, 1}. Make autocorrelation from 1st to 3rd order (CR). How to generate these correlations in R?
T=500
e=rnorm(T)
phi1=.5
phi2=.9
phi3=1
c=3
y1=matrix(0,T,1)
y1[1]=e[1]
for(i in 2:T){y1[i]=c+phi1*y1[i-1]+e[i]}
y2=matrix(0,T,1)
y2[1]=e[1]
for(i in 2:T){y2[i]=c+phi2*y2[i-1]+e[i]}
y3=matrix(0,T,1)
y3[1]=e[1]
for(i in 2:T){y3[i]=c+phi3*y3[i-1]+e[i]}
y1[i-1]=lag(y1[i],-1)
y2[i-1]=lag(y2[i],-1)
y3[i-1]=lag(y3[i],-1)
y88=cbind(y1[i],y2[i],y3[i])
y88
lm(y88[,1]~y88[,2])
cor(y1[i],y1[i-1])
When I do this the correction presents NA result. Would anyone have any tips?