n = 100 ## The sample size. t2 = 1 ## The error variance. alpha = 0.5 ## The AR(1) coefficient. ## The data variance. s2 = t2 / (1 - alpha^2) ## Simulate the first value. X = rnorm(1, sd=sqrt(s2)) ## Simulate the rest of the sequence. for (i in 2:n) { X[i] = alpha*X[i-1] + rnorm(1, sd=sqrt(t2)) }