@@ -103,18 +103,35 @@ c22 = crosscor(x2, x2)
103
103
@test crosscor (x, x) ≈ cat ([c11 c21], [c12 c22], dims= 3 )
104
104
105
105
106
- # # pacf
107
-
108
- pacfr = [- 1.598495044296996e-03 - 2.915104118351207e-01im
109
- - 5.560162016912027e-01 + 2.950837739894279e-01im
110
- - 2.547001916363494e-02 + 2.326084658014266e-01im
111
- - 5.427443903358727e-01 + 3.146715147305132e-01im ];
112
-
113
- @test pacf (x1, 1 : 4 ) ≈ pacfr[1 : 4 ]
114
-
115
- pacfy = [- 1.598495044296996e-03 - 2.915104118351207e-01im
116
- - 5.560162016912027e-01 + 2.950837739894279e-01im
117
- - 2.547001916363494e-02 + 2.326084658014266e-01im
118
- - 5.427443903358727e-01 + 3.146715147305132e-01im ];
119
-
120
- @test pacf (x1, 1 : 4 , method= :yulewalker ) ≈ pacfy
106
+ # # pacf least squares
107
+ pacf_ls = [- 1.598495044296996e-03 - 2.915104118351207e-01im
108
+ - 5.560162016912027e-01 + 2.950837739894279e-01im
109
+ - 2.547001916363494e-02 + 2.326084658014266e-01im
110
+ - 5.427443903358727e-01 + 3.146715147305132e-01im ]
111
+
112
+ @test pacf (x1, 1 : 4 ) ≈ pacf_ls[1 : 4 ]
113
+
114
+ # # pacf Yule-Walker
115
+
116
+ function yulewalker_qr (v:: AbstractVector )
117
+ A = toeplitz (v)
118
+ b = v[2 : end ]
119
+ x = - A\ b
120
+ end
121
+ function toeplitz (v:: AbstractVector{T} ) where T
122
+ N= length (v)
123
+ A = zeros (T, N - 1 , N - 1 )
124
+ for n in 1 : N- 1
125
+ A[n, n + 1 : end ] = conj (v[2 : N- n])
126
+ A[n, 1 : n] = reverse (v[1 : n])
127
+ end
128
+ return A
129
+ end
130
+ # durbin solver
131
+ acf = autocor (x1)
132
+ p = [yulewalker_qr (acf[1 : n])[n- 1 ] for n in 2 : length (acf)]
133
+ @test p ≈ StatsBase. durbin (acf[2 : end ])
134
+
135
+ pacfy = [];
136
+
137
+ @test pacf (x1, 1 : 4 , method= :yulewalker ) ≈ - p[1 : 4 ]
0 commit comments