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

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:

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?

• @Rali could you explain what your notation stands for. In particular, what these $\delta_i$s are. Jul 29, 2017 at 20:14
• @Taylor the matrix represents variance covariance matrix of an unevenly spaced time series. The deltas represent the time gaps between the observations. e.g. delta_1 is the space between observations y_1 and y_2. I'm assuming an AR(1) process and Phi is the parameter.
– Rali
Jul 29, 2017 at 20:29
• @Rali ok cool then this is not a toeplitz matrix. Idk if the function still handles this situation, though Jul 29, 2017 at 20:47

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,"-"))

• Thank you! using the cumsum for the powers vector followed by outer solved the problem.
– Rali
Aug 2, 2017 at 11:45
• Is this true for AR(1) specifically? Do you have a recommendation for further reading? Feb 26, 2019 at 21:13
• Yes, the above equation is only true for an AR(1) model. For further reading, search this site for "time series textbook". Feb 26, 2019 at 21:22