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)
M(ranking = seq_len(dim), dim)
Arguments
- cov, cov_diff
[
matrix()
]
A (differenced) covariance matrix of dimensiondim
(ordim
- 1, respectively).- ref
[
integer(1)
]
The reference row between1
anddim
for differencing that mapscov
tocov_diff
, see details.- dim
[
integer(1)
]
The matrix dimension.- ranking
[
integer()
]
The integers1
todim
in arbitrary order.
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 \(k\)th 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 \(-1\)s 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)
.
As a alternative to \(\Delta_k\), the function M()
returns a matrix for
taking differences such that the resulting vector is negative.
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 <- 4
Sigma <- sample_covariance_matrix(dim = n)
k <- 2
x <- c(1, 3, 2, 4)
# build difference operator
delta_k <- delta(ref = k, dim = n)
# difference vector
delta_k %*% x
#> [,1]
#> [1,] -2
#> [2,] -1
#> [3,] 1
# difference Sigma
(Sigma_diff <- diff_cov(Sigma, ref = k))
#> [,1] [,2] [,3]
#> [1,] 7.598265 1.545601 5.552754
#> [2,] 1.545601 3.668382 5.568672
#> [3,] 5.552754 5.568672 10.721597
# un-difference Sigma
(Sigma_0 <- undiff_cov(Sigma_diff, ref = k))
#> [,1] [,2] [,3] [,4]
#> [1,] 7.598265 0 1.545601 5.552754
#> [2,] 0.000000 0 0.000000 0.000000
#> [3,] 1.545601 0 3.668382 5.568672
#> [4,] 5.552754 0 5.568672 10.721597
# difference again
Sigma_diff_2 <- diff_cov(Sigma_0, ref = k)
all.equal(Sigma_diff, Sigma_diff_2)
#> [1] TRUE
# difference such that the resulting vector is negative
M(ranking = order(x, decreasing = TRUE), dim = n) %*% x
#> [,1]
#> [1,] -1
#> [2,] -1
#> [3,] -1