Learn R Programming

FluxPoint (version 0.1.2)

get_Sigs: Compute the covariance matrix \(\Sigma_{\mathrm{ALL}}^*\) for observations within a moving window

Description

Calculates the covariance matrix \(\Sigma_{\mathrm{ALL}}^*\) for all observations within a moving window of length \(w\), given the random walk innovation covariance \(\Sigma_{\boldsymbol{\eta}}\), the VAR(1) innovation covariance \(\Sigma_{\boldsymbol{\nu}}\), the autoregressive coefficient matrix \(\Phi\), and the initial-state covariance matrix \(\Gamma_{\boldsymbol{\epsilon}}(0)\) (denoted here by `Sig_e1`). The resulting matrix accounts for both the random walk component and the temporal dependence introduced by the VAR(1) structure.

Usage

get_Sigs(w, p, Sig_eta, Sig_nu, Phi, Sig_e1)

Value

A list with the following components:

  • `Sig_AR` — Covariance contribution from the VAR(1) component (\(\Sigma_{\mathrm{AR}}\)).

  • `Sig_RW` — Covariance contribution from the random walk component (\(\Sigma_{\mathrm{RW}}\)).

  • `Sig_all` — Combined covariance matrix (\(\Sigma_{\mathrm{ALL}}^* = \Sigma_{\mathrm{AR}} + \Sigma_{\mathrm{RW}}\)).

  • `Sig_all_inv` — Inverse of the combined covariance matrix \((\Sigma_{\mathrm{ALL}}^*)^{-1}\).

Arguments

w

Integer; window size.

p

Integer; data dimension.

Sig_eta

Numeric \(p \times p\) matrix representing the covariance of the random walk innovation \(\Sigma_{\boldsymbol{\eta}}\).

Sig_nu

Numeric \(p \times p\) matrix representing the covariance of the VAR(1) innovation \(\Sigma_{\boldsymbol{\nu}}\).

Phi

Numeric \(p \times p\) autoregressive coefficient matrix \(\Phi\).

Sig_e1

Numeric \(p \times p\) matrix representing the covariance of the initial state \(\Gamma_{\boldsymbol{\epsilon}}(0)\).

Details

The function decomposes the overall covariance matrix \(\Sigma_{\mathrm{ALL}}^*\) into two additive components corresponding to the random walk contribution \(\Sigma_{\mathrm{RW}}\) and the autoregressive contribution \(\Sigma_{\mathrm{AR}}\), so that $$\Sigma_{\mathrm{ALL}}^* = \Sigma_{\mathrm{RW}} + \Sigma_{\mathrm{AR}}.$$ When \(p = 1\), the construction reduces to the scalar random walk and AR(1) case, for which closed-form covariance expressions are available. For higher-dimensional settings, block-matrix structures are constructed using functions from the blockmatrix package to capture both cross-sectional and temporal dependence. The returned inverse matrix \((\Sigma_{\mathrm{ALL}}^*)^{-1}\) is used in the main change point detection algorithm to adjust for the effects of random walk drift and vector autoregressive correlation.

Examples

Run this code
set.seed(1)
p <- 3
w <- 20
Sig_eta <- diag(0.01, p)
Sig_nu  <- random_Signu(p, 0)
Phi <- random_Phi(p, p)
Sig_e1 <- get_Sig_e1_approx(Sig_nu, Phi)
res <- get_Sigs(w, p, Sig_eta, Sig_nu, Phi, Sig_e1)

Run the code above in your browser using DataLab