|
epinowcast
|
Go to the source code of this file.
Functions | |
| vector | pacf_to_phi (vector r) |
| vector | arma_impulse (vector phi, vector theta, int T) |
| matrix | lower_toeplitz (vector psi) |
| matrix | cumulative_op (int T, int d) |
| matrix | arima_kernel_matrix (vector phi, vector theta, int d, int T) |
| matrix | arima_filter (matrix Z, vector phi, vector theta, int d) |
| vector | apply_arima_residual (vector base, int n_obs, int present, int T, int G, int p, int d, int q, matrix z, vector pacf, vector theta, array[] real sigma, array[] int flat_idx) |
| vector apply_arima_residual | ( | vector | base, |
| int | n_obs, | ||
| int | present, | ||
| int | T, | ||
| int | G, | ||
| int | p, | ||
| int | d, | ||
| int | q, | ||
| matrix | z, | ||
| vector | pacf, | ||
| vector | theta, | ||
| array[]real | sigma, | ||
| array[]int | flat_idx ) |
Add an ARIMA(p, d, q) latent residual to a per-observation predictor.
Encapsulates the kernel build, scaling, and per-observation lookup so module call sites are a single line. When present is 0 the input is returned unchanged.
| base | Predictor to which the latent is added. |
| n_obs | Length of base and of the lookup vectors. |
| present | 0 = inert, 1 = active. |
| T | Number of time points in the latent series. |
| G | Number of groups. |
| p,d,q | ARIMA orders. |
| z | Unit-normal shocks (T x G). |
| pacf | Partial autocorrelations on (-1, 1), length p. |
| theta | MA coefficients, length q. |
| sigma | Length-1 array (empty when not present) holding the latent standard deviation. |
| time_idx | Per-observation time index in 1..T. |
| group_idx | Per-observation group index in 1..G. |
base + sigma * (D^d * T(psi)) * z looked up at the per-observation indices. Definition at line 185 of file arima_kernel.stan.
| matrix arima_filter | ( | matrix | Z, |
| vector | phi, | ||
| vector | theta, | ||
| int | d ) |
Apply the ARIMA(p, d, q) kernel to a (T, G) matrix of shocks.
Each column is filtered independently through the same kernel. For per-group phi / theta (independent type), call this once per group with the appropriate column.
When p = q = 0 (pure differencing, ARIMA(0, d, 0)) the operation reduces to repeated cumulative sums per column, which avoids materialising the T x T kernel matrix and saves O(T^2) work per iteration. This makes ARIMA(0, 1, 0) — the random-walk equivalent — cost O(T G) per evaluation instead of O(T^2 G).
Definition at line 145 of file arima_kernel.stan.
| matrix arima_kernel_matrix | ( | vector | phi, |
| vector | theta, | ||
| int | d, | ||
| int | T ) |
Build the full ARIMA(p, d, q) kernel.
Returns the T x T lower-triangular matrix that maps unit-normal shocks to the latent ARIMA series. The d-fold integration is applied as d repeated cumulative_sum() calls on the columns of the ARMA Toeplitz, which is mathematically identical to D^d * T(psi) but skips both the construction of the D^d matrix and the dense matrix-matrix multiply that follows it. For d = 0 no integration pass is taken.
Definition at line 121 of file arima_kernel.stan.
| vector arma_impulse | ( | vector | phi, |
| vector | theta, | ||
| int | T ) |
Truncated impulse response of the ARMA(p, q) process up to lag T-1.
Returns a length-T vector psi with psi[1] = 1 and the remaining entries given by the standard ARMA recursion.
Definition at line 59 of file arima_kernel.stan.
| matrix cumulative_op | ( | int | T, |
| int | d ) |
Build the d-fold cumulative-sum operator (lower triangular).
Provided as a utility; the ARIMA kernel path no longer materialises this matrix per iteration. arima_kernel_matrix() instead applies cumulative_sum() to the columns of the ARMA Toeplitz, avoiding both the D^d build and the dense T x T multiply that follows it.
Definition at line 99 of file arima_kernel.stan.
| matrix lower_toeplitz | ( | vector | psi | ) |
Build the lower-triangular Toeplitz matrix from a length-T impulse response.
Uses column-wise vector-slice assignment (one assignment per column) rather than scalar element loops, so the inner work runs through Stan's vectorised primitives.
Definition at line 82 of file arima_kernel.stan.
| vector pacf_to_phi | ( | vector | r | ) |
ARIMA(p, d, q) kernel for regression-style residual modelling.
The full kernel maps a vector of unit-normal shocks z to a series eps = K(phi, theta, d) * z where the linear predictor receives eps[time_idx, group_idx] for each observation. The kernel factorises as D^d * T(psi), where:
psi is the truncated impulse response of the ARMA(p, q) process with autoregressive coefficients phi and moving-average coefficients theta. It satisfies the recursion psi[1] = 1,
psi[k] = sum_{j=1..min(p,k-1)} phi[j] * psi[k-j]
+ (k-1 <= q ? theta[k-1] : 0).
T(psi) is the lower-triangular Toeplitz matrix with first column psi. Multiplying it by a shock vector applies the ARMA filter.D is the lower-triangular matrix of ones (cumulative-sum operator). D^d integrates d times. D^0 is the identity.Stationarity of the AR(p) component is enforced via the partial autocorrelation parameterisation of Barndorff-Nielsen and Schou (1973): given partial autocorrelations r in (-1, 1), the Durbin-Levinson recursion produces stationary phi. Convert partial autocorrelations to AR coefficients.
Implements the Durbin-Levinson recursion in its forward direction. Inputs r[k] in (-1, 1) for k = 1..p map bijectively to phi giving a stationary AR(p) process.
Definition at line 36 of file arima_kernel.stan.