@@ -171,6 +171,31 @@ function sarma_reparam(θ, Θ, s, activeLags = nothing; ztrans = "monahan",
171171end
172172
173173
174+ # Compute AR parameters from partial autocorrelations
175+ function arma_reparam_partials (P:: Vector ; negative_signs = true )
176+ p = length (P)
177+ if negative_signs
178+ P = - P
179+ end
180+ ϕ = zeros (eltype (P), p, p) # Not sure we even need to allocate, but let's not worry about that.
181+ ϕ[1 ,1 ] = P[1 ]
182+ for k = 2 : p
183+ for j = 1 : k
184+ if k == j
185+ ϕ[k, j] = P[k]
186+ else
187+ ϕ[k, j] = ϕ[k- 1 , j] + P[k]* ϕ[k- 1 , k- j]
188+ end
189+ end
190+ end
191+ if negative_signs
192+ return - ϕ[end ,:] # returns ϕ in polynomial ϕ(B) = 1 - ϕ₁B - ϕ₂B² - .... used for AR
193+ else
194+ return ϕ[end ,:] # returns ϕ in polynomial ϕ(B) = 1 + ϕ₁B + ϕ₂B² + ... used for MA
195+ end
196+ end
197+
198+
174199"""
175200 Arima(y; order = [0,0,0], seasonal = [0,0,0], xreg = nothing, include_mean = true,
176201 include_drift = false, include_constant = true, frequency = 1, deltat = 1)
@@ -435,4 +460,26 @@ function SpecDensARTFIMA(ω, ϕ, θ, d, λ, σ²)
435460 specDens = (σ²/ (2 π))* (abs (MApoly (exp (- im* ω)))^ 2 / abs (ARpoly (exp (- im* ω)))^ 2 )*
436461 abs (1 - exp (- (λ+ im* ω)))^ (- 2 * d)
437462 return specDens
438- end
463+ end
464+
465+
466+ """
467+ Simulate from a uniform prior for AR(p) over stationary region by simulating partials.
468+ """
469+ function sim_uniformAR (p, nsim, trans = " monahan" )
470+ if (trans != " monahan" )
471+ error (" Only 'monahan' transformation is currently implemented" )
472+ end
473+
474+ Psim = zeros (nsim,p)
475+ ϕsim = zeros (nsim,p)
476+ betadists = []
477+ for k = 1 : p
478+ push! (betadists, - 1 + 2 * Beta ((k+ 1 )/ 2 , floor (k/ 2 ) + 1 ))
479+ end
480+ for i = 1 : nsim
481+ Psim[i,:] = rand .(betadists)
482+ ϕsim[i,:] = arma_reparam_partials (Psim[i,:])
483+ end
484+ return ϕsim, Psim
485+ end
0 commit comments