Ankur Goel

On hunt of awesomeness!

Levinson-Durbin and Autocovariance

As discussed, I am implementing estimation methods for phi in AR modelling. We covered yule_walker earlier, I’ll write a post about that. After it’s implementation, we go ahead with another estimation method - Levinson Durbin

Levinson-Durbin requires timeline series to be demeaned(series = series - series.mean) and it’s autocovavirance.

Autocovariance of series is represented by summation of summation of product of series with series at lag k. That is, summation of (x_i * x_{i+lag}). It is also directly related with acf of series as acf(k) = acvf(h) / acvf(0). It’s code can now be found in Statsample::TimeSeries’s acvf method.

Now, with the help of autocovariance series, our levinson_durbin function recursively computes the following parameters:

  • sigma_v : estimation of error variance
  • arcoefs : AR phi values for timeseries
  • pac : unbiased levinson pacf estiation
  • sigma : sigma for AR.

L-D performs recursive matrix and vector multiplications to populate it’s toeplitz matrix. Here is some code depicting those manipulations:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
      order = nlags
      phi = Matrix.zero(nlags + 1)
      sig = Array.new(nlags+1)

      #setting initial point for recursion:
      phi[1,1] = series[1]/series[0]
      #phi[1][1] = series[1]/series[0]
      sig[1] = series[0] - phi[1, 1] * series[1]

      2.upto(order).each do |k|
        phi[k, k] = (series[k] - (Statsample::Vector.new(phi[1...k, k-1]) * series[1...k].reverse.to_ts).sum) / sig[k-1]
        #some serious refinement needed in above for matrix manipulation. Will do today
        1.upto(k-1).each do |j|
          phi[j, k] = phi[j, k-1] - phi[k, k] * phi[k-j, k-1]
        end
        sig[k] = sig[k-1] * (1-phi[k, k] ** 2)

      end

Implementation can be found here.

Now, in this week, I will integrate this in AR modelling and perform some tests to verify the estimation. And will soon start with next estimation method :)

Cheers,
Ankur Goel