(reproducible example added)
I tried to code the AR(1) model Yt=0.6Yt-1+Vt (Vt ~ N(0,1)).
# Function that makes (mean,sd) of a sample drawn from population exactly
# same with those of the population
rnorm2 <- function(n,mean,sd) { mean + sd*scale(rnorm(n)) }
N <- 1388; ro <- 0.6; a <- 0
set.seed(1)
v <- ts(rnorm2(N,0,1)) # white noise, v~N(0,1)
c(mean(v),sd(v)) # 1.160729e-17 = 0; 1.000000e+00 = 1
y <- ts(rep(0,N)) # y[1]:=0 defined
for (t in 2:N){ y[t] <- a + ro*y[t-1]+v[t] }
After arranging rnorm
function in the desired way as rnorm2
as above, I expected to obtain the mean and standard deviation of y as follows:
Mean(Yt) = alfa/(1-ρ)
a/(1-ro) # 0
StdDev(Yt)=sqrt[sd(v)2/(1-ρ2)]
sqrt(sd(v)^2/(1-(0.6)^2)) # 1.25
But, I get:
c(mean(y),sd(y)) # 0.002486451 1.227402426
Why are those mean and standard deviation different (0.002486451<>0; 1.227402426<>1.25)?