These functions difference and un-difference a covariance matrix with respect
to row ref
.
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.
Details
For differencing: Let \(\Sigma\) be a covariance matrix of dimension
\(n\). Then $$\tilde{\Sigma} = \Delta_k \Sigma \Delta_k'$$
is the differenced covariance matrix with respect to row \(k = 1,\dots,n\),
where \(\Delta_k\) is a difference operator that depends on the reference
row \(k\). More precise, \(\Delta_k\) the identity matrix of dimension
\(n\) without row \(k\) and with \(-1\)s in column \(k\).
It can be computed with delta(ref = k, dim = n)
.
For un-differencing: The "un-differenced" covariance matrix \(\Sigma\) cannot be uniquely computed from \(\tilde{\Sigma}\). For a non-unique solution, we add a column and a row of zeros at column and row number \(k\) to \(\tilde{\Sigma}\), respectively, and add \(1\) to each matrix entry to make the result a proper 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
# build difference operator
delta(ref = k, dim = n)
#> [,1] [,2] [,3]
#> [1,] 1 -1 0
#> [2,] 0 -1 1
# difference Sigma
(Sigma_diff <- diff_cov(Sigma, ref = k))
#> [,1] [,2]
#> [1,] 7.011921 1.6136129
#> [2,] 1.613613 0.9099336
# un-difference Sigma
undiff_cov(Sigma_diff, ref = k)
#> [,1] [,2] [,3]
#> [1,] 8.011921 1 2.613613
#> [2,] 1.000000 1 1.000000
#> [3,] 2.613613 1 1.909934