diff_cov: Difference and un-difference covariance matrix

View source: R/covariance_differencing.R

diff_covR Documentation

Difference and un-difference covariance matrix

Description

These functions difference and un-difference random vectors and covariance matrices.

Usage

diff_cov(cov, ref = 1)

undiff_cov(cov_diff, ref = 1)

delta(ref = 1, dim)

Arguments

cov, cov_diff

[matrix()]
A (differenced) covariance matrix of dimension dim (or dim - 1, respectively).

ref

[integer(1)]
The reference row between 1 and dim for differencing that maps cov to cov_diff, see details.

dim

[integer(1)]
The matrix dimension.

Details

Assume x \sim N(0, \Sigma) is a multivariate normally distributed random vector of dimension n. We may want to consider the differenced vector

\tilde x = (x_1 - x_k, x_2 - x_k, \dots, x_n - x_k)',

excluding the kth element (hence, \tilde x is of dimension (n - 1) \times 1). Formally, \tilde x = \Delta_k x, where \Delta_k is a difference operator that depends on the reference row k. More precise, \Delta_k is the identity matrix of dimension n without row k and with -1s in column k. The difference operator \Delta_k can be computed via delta(ref = k, dim = n).

Then, \tilde x \sim N(0, \tilde \Sigma), where

\tilde{\Sigma} = \Delta_k \Sigma \Delta_k'

is the differenced covariance matrix with respect to row k = 1,\dots,n. The differenced covariance matrix \tilde \Sigma can be computed via diff_delta(Sigma, ref = k).

Since \Delta_k is a non-bijective mapping, \Sigma cannot be uniquely restored from \tilde \Sigma. However, it is possible to compute a non-unique solution \Sigma_0, such that \Delta_k \Sigma_0 \Delta_k = \tilde \Sigma. For such a non-unique solution, we add a column and a row of zeros at column and row number k to \tilde{\Sigma}, respectively. An "un-differenced" covariance matrix \Sigma_0 can be computed via undiff_delta(Sigma_diff, ref = k).

Value

A (differenced or un-differenced) covariance matrix.

See Also

Other matrix helpers: check_correlation_matrix(), check_covariance_matrix(), check_transition_probability_matrix(), cov_to_chol(), insert_matrix_column(), matrix_diagonal_indices(), matrix_indices(), sample_correlation_matrix(), sample_covariance_matrix(), sample_transition_probability_matrix(), stationary_distribution()

Examples

n <- 3
Sigma <- sample_covariance_matrix(dim = n)
k <- 2
x <- c(1, 3, 2)

# build difference operator
delta_k <- delta(ref = k, dim = n)

# difference vector
delta_k %*% x

# difference Sigma
(Sigma_diff <- diff_cov(Sigma, ref = k))

# un-difference Sigma
(Sigma_0 <- undiff_cov(Sigma_diff, ref = k))

# difference again
Sigma_diff_2 <- diff_cov(Sigma_0, ref = k)
all.equal(Sigma_diff, Sigma_diff_2)

oeli documentation built on Oct. 16, 2024, 5:08 p.m.