(reproducible example added)
I tried to model Yt=0.6Yt-1+Vt (Vt ~ N(0,1)) AR(1) with three different techniques.
1. The formula Yt =ρt[y1/ρ + ∑j=2 to t (α+Vj)/ρj] of Yt=α+ρYt-1+Vt obtained via back substitution and using cumulative sum.
2. The classical for
loop
3. arima.sim
simulation.
While I expect to get more or less the same things, interesting and unexpected things happened:
N <- 1388; ro <- 0.6; a <- 0
set.seed(1)
v <- ts(rnorm(N,0,1))
# Formula technique
y1 <- ts(rep(0,N)) # y[1]:=0 defined
y1[-1] <- ro^(2:N) * (y1[1]/ro + cumsum((a+v[-1]) / ro^(2:N)))
# The classical "for" loop
y2 <- ts(rep(0,N)) # y2[1]:=0 defined
for (t in 2:N){ y2[t] <- a + ro*y2[t-1]+v[t] }
# arima.sim simulation
set.seed(1)
y3 <- arima.sim(model=list(ar=0.6), n=1388, mean=0, sd=sqrt(1))
# change n in arima.sim accordingly such that n=N simultaneously with the N definition above
c(mean(y1),sd(y1))
c(mean(y2),sd(y2))
c(mean(y3),sd(y3))
N=1388 (and n=1388) gives:
[1] -0.03713488 1.26102077
[1] -0.03713488 1.26102077
[1] -0.01048798 1.28445899
N=1389 (and n=1389) gives:
[1] Inf NaN
[1] -0.03661779 1.26071373
[1] -0.01048798 1.28445899
The standard deviation values are just as expected:
StdDev(Yt)=sqrt[sd(v)2/(1-ρ2)]
sqrt(sd(v)^2/(1-(0.6)^2)) # 1.284229
Strangenesses appear for the formula technique:
c(mean(y1),sd(y1))
is defined for N<=1388
c(mean(y1),sd(y1))
is (Inf, NaN) for N=1389 and N=1390
c(mean(y1),sd(y1))
is (NaN, NA) for N>=1391.
Question:
1. Why do the formula technique fail for N>=1989?
(though we have a stationary series with ρ=0.6)
2. Why do we get c(mean(y1),sd(y1))#(Inf, NaN)
for N=1389 and N=1390 and
c(mean(y1),sd(y1))#(NaN, NA)
for N>=1391?