permute_var {mcompanion} | R Documentation |
Permute rows and columns of matrices
Description
Permute rows and columns of matrices.
Usage
permute_var(mat, perm = nrow(mat):1)
permute_synch(param, perm)
Arguments
mat |
a matrix. |
param |
a matrix or list, see Details. |
perm |
permutation, defaults to |
Details
Given a permutation, permute_var
permutes the rows and columns
of a matrix in such a way that if mat
is the covariance matrix
of a vector x
, then the rearranged matrix is the covariance
matrix of x[perm]
. If P
is the permutation matrix
corresponding to perm
, then the computed value is
P %*% mat %*% t(P)
.
permute_synch
performs the above transformation on all matrices
found in param
. More precisely, if param
is a matrix,
then the result is the same as for permute_var
. Otherwise
param
should be a list and, conceptually, permute_synch
is
applied recursively on each element of this list. The net result is
that each matrix, say M
, in param
is replaced by
PMP'
and each vector, say v
, by Pv
. The idea is that
param
may contain specification of a VAR model, all components
of which need to be reshuffled if the components of the multivariate
vector are permuted.
All matrices in param
must have the same number of rows, say
d
, but this is not checked. perm
should be a permutation
of 1:d
.
Value
for permute_var
, a matrix,
for permute_synch
, a matrix or list of the same shape as
param
in which each matrix is transformed as described in
Details.
Author(s)
Georgi N. Boshnakov
Examples
Cl <- cor(longley) # from example for 'cor()'
nc <- ncol(Cl)
v <- 1:nc
names(v) <- colnames(Cl)
permute_var(Cl)
all(permute_var(Cl) == Cl[ncol(Cl):1, ncol(Cl):1])