2
$\begingroup$

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?

$\endgroup$
  • $\begingroup$ @Rali could you explain what your notation stands for. In particular, what these $\delta_i$s are. $\endgroup$ – Taylor Jul 29 '17 at 20:14
  • $\begingroup$ @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. $\endgroup$ – Rali Jul 29 '17 at 20:29
  • 1
    $\begingroup$ @Rali ok cool then this is not a toeplitz matrix. Idk if the function still handles this situation, though $\endgroup$ – Taylor Jul 29 '17 at 20:47
8
$\begingroup$

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,"-"))
$\endgroup$
  • 2
    $\begingroup$ Thank you! using the cumsum for the powers vector followed by outer solved the problem. $\endgroup$ – Rali Aug 2 '17 at 11:45
  • $\begingroup$ Is this true for AR(1) specifically? Do you have a recommendation for further reading? $\endgroup$ – StatsSorceress Feb 26 at 21:13
  • $\begingroup$ Yes, the above equation is only true for an AR(1) model. For further reading, search this site for "time series textbook". $\endgroup$ – Jarle Tufto Feb 26 at 21:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.