Skip to content

Commit 8c60eb4

Browse files
added sim from uniform AR prior
1 parent a06cb39 commit 8c60eb4

File tree

2 files changed

+50
-3
lines changed

2 files changed

+50
-3
lines changed

src/ARIMAUtils.jl

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,31 @@ function sarma_reparam(θ, Θ, s, activeLags = nothing; ztrans = "monahan",
171171
end
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

src/TimeSeriesUtils.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ export ℓwhittle
2020
export simProcessSpectral
2121

2222
include("ARIMAUtils.jl")
23-
export ARMAacf, arma_reparam, inv_arma_reparam, check_stationarity
24-
export sarma_reparam
23+
export ARMAacf, arma_reparam, inv_arma_reparam, arma_reparam_partials, sarma_reparam
24+
export check_stationarity, sim_uniformAR
2525
export Arima, simARMA, ℓARMA
2626
export SpecDensARMA, SpecDensSARMA, SpecDensMultiSARMA, SpecDensARTFIMA
2727

0 commit comments

Comments
 (0)