commat function

Commutation matrix

Commutation matrix

This function returns the (rc×rcr c \times r c) commutation matrix P\mathbf{P} such that P\mboxvec(Y)=\mboxvec(Y),\mathbf{P} \mbox{vec}(\mathbf{Y}) = \mbox{vec}(\mathbf{Y}'),

where Y\mathbf{Y} is a (r×cr \times c) matrix (Magnus and Neudecker, 2019).

commat(r, c)

Arguments

  • r: Number of rows of Y\mathbf{Y}.
  • c: Number of columns of Y\mathbf{Y}.

Returns

A sparse (rc×rcr c \times r c) matrix, P\mathbf{P}.

Examples

Y <- matrix(rnorm(30), 5, 6) P <- commat(5, 6) P %*% as.vector(Y) == as.vector(t(Y)) # check

References

Magnus, J.R. and Neudecker, H. (2019), Matrix Differential Calculus with Applications in Statistics and Econometrics, third edition, New York, Wiley, pp. 54-55.

See Also

Utilities: FoReco2matrix(), aggts(), balance_hierarchy(), csprojmat(), cstools(), ctprojmat(), cttools(), df2aggmat(), lcmat(), recoinfo(), res2matrix(), shrink_estim(), teprojmat(), tetools(), unbalance_hierarchy()