[R] Create an AR(1) covariance matrix

Rick DeShon deshon at msu.edu
Fri May 11 16:29:50 CEST 2007


Hi All.

I need to create a first-order autoregressive covariance matrix
(AR(1)) for a longitudinal mixed-model simulation.  I can do this
using nested "for" loops but I'm trying to improve my R coding
proficiency and am curious how it might be done in a more elegant
manner.

To be clear, if there are 5 time points then the AR(1) matrix is 5x5
where the diagonal is a constant variance (sigma^2) and the
covariances depend on the number of "steps" between trials.  So, the
first off-diagonal of the matrix is sigma*rho, the second off-diagonal
is sigma*rho^2, the third off-diagonal is sigma*rho^3, and so forth.

Any suggestions for an elegant method to flexibly create this matrix?

Rick DeShon



More information about the R-help mailing list