## Generate nrep datasets from an AR(1) process. arsim = function(alpha, t2, nrep, n) { ## The data variance. s2 = t2 / (1 - alpha^2) ## Storage for nrep dependent sequences of length n, each stored ## in a row of X. X = array(0, c(nrep,n)) ## Simulate the first value. X[,1] = rnorm(nrep, sd=sqrt(s2)) ## Simulate the rest of the sequence. for (i in (2:n)) { X[,i] = alpha*X[,i-1] + rnorm(nrep, sd=sqrt(t2)) } return(X) }