Solved – How to write variance covariance matrix of AR(1) process in R

autoregressivecovariance-matrixmatrixrtime series

I'm trying to write autocovariance matrix of AR(1) process in R and I'm having difficulty. The autocovariance matrix that I'm using in my project takes the form as shown in the picture:

enter image description here

I also formed an example matrix of size n=5 for simplification and that's what I'm trying to code on R. I'm new to forming equations and matrices on R. I have an idea on where to start in terms of forming a diagonal matrix but my problem is in the power of the elements of the matrix, I'm unable to come up with a method to automate the power of each element. Any ideas here?

Best Answer

The covariance between an observation at time $t_i$ and time $t_j$ is $$ \frac{\sigma^2}{1-\phi^2}\phi^{|t_i-t_j|} $$ If the delta's are time gaps between the time points $t_1,t_2,\dots,t_5$, then each $t_i$ are given by cumulative sums of the delta's. In R do

delta <- c(0,1,3,4,8)
phi <- .5
sigma <- 1
t <- cumsum(delta)
Sigma <- sigma^2/(1-phi^2)*phi^abs(outer(t,t,"-"))