Skip to contents

Helpers for a two-dimensional (2D) AR1 process, with separable correlation across years and ages. TAM uses these helpers only for process = "ar1"; IID processes use Normal densities and draws directly.

  • dprocess_ar1() returns the log-density contribution for a given matrix x.

  • rprocess_ar1() generates a matrix draw with the requested dependence structure.

Usage

dprocess_ar1(x, phi = c(0, 0), sd = 1)

rprocess_ar1(ny, na, phi = c(0, 0), sd = 1)

Arguments

x

A numeric matrix (\(n_y \times n_a\)) of process residuals for dprocess_ar1().

phi

Length-2 numeric vector c(phi_age, phi_year) with values in \((-1, 1)\) for AR(1); zero gives independence.

sd

Positive innovation-scale SD \(\sigma\); the marginal SD is \(\sigma/\sqrt{(1-\phi_\text{age}^2)(1-\phi_\text{year}^2)}\).

ny, na

Positive integers: numbers of years and ages for rprocess_ar1().

Value

  • dprocess_ar1(): a single numeric log-density value.

  • rprocess_ar1(): a numeric matrix of dimension \(n_y \times n_a\).

Details

Separable AR1 process: density and simulation

Let \(X \in \mathbb{R}^{n_y \times n_a}\) denote the process on year (\(y\)) and age (\(a\)) indices. It follows a stationary separable AR(1) in both dimensions with correlations \(\phi_\text{age}\) (columns) and \(\phi_\text{year}\) (rows), satisfying \(|\phi|<1\).

The implied covariance is $$\mathrm{Cov}\{\mathrm{vec}(X)\} = \frac{\sigma^2}{(1-\phi_\text{age}^2)(1-\phi_\text{year}^2)} \; \Sigma_\text{age} \otimes \Sigma_\text{year},$$

where \(\Sigma_\cdot\) are AR(1) correlation matrices with entries \(\phi^{|i-j|}\).

Examples

# Simulate then calculate log-density
set.seed(1)
X_ar1 <- rprocess_ar1(ny = 10, na = 8, sd = 0.3, phi = c(0.5, 0.9))
dprocess_ar1(X_ar1, sd = 0.3, phi = c(0.5, 0.9))
#> [1] -17.78236