FoReco (version 0.1.1)

commat: Commutation matrix

Description

This function returns the ((r c) x (r c)) commutation matrix P such that $$P vec(Y) = vec(Y'),$$ where Y is a (r x c) matrix.

Usage

commat(r, c)

Arguments

r

Number of rows of Y.

c

Number of columns of Y.

Value

A sparse ((r c) x (r c)) matrix.

References

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

Examples

Run this code
# NOT RUN {
Y <- matrix(rnorm(30), 5, 6)
P <- commat(5, 6)
P %*% as.vector(Y) == as.vector(t(Y)) # check
# }

Run the code above in your browser using DataCamp Workspace