View source: R/covariance_differencing.R
| diff_cov | R Documentation |
These functions difference and un-difference random vectors and covariance matrices.
diff_cov(cov, ref = 1)
undiff_cov(cov_diff, ref = 1)
delta(ref = 1, dim)
M(ranking = seq_len(dim), dim)
cov, cov_diff |
[ |
ref |
[ |
dim |
[ |
ranking |
[ |
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).
As a alternative to \Delta_k, the function M() returns a matrix for
taking differences such that the resulting vector is negative.
A (differenced or un-differenced) covariance matrix.
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()
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
# 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)
# difference such that the resulting vector is negative
M(ranking = order(x, decreasing = TRUE), dim = n) %*% x
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.