Learn R Programming

ks (version 1.6.13)

vec, vech, invvec, invvech: Vector and vector half operators

Description

The vec (vector) operator takes a $d \times d$ matrix and stacks the columns into a single vector of length $d^2$. The vech (vector half) operator takes a symmetric $d \times d$ matrix and stacks the lower triangular half into a single vector of length $d(d+1)/2$.

The functions invvec and invvech are the inverses of vec and vech i.e. they form matrices from vectors.

Usage

vec(x, byrow = FALSE)
vech(x)
invvec(x, ncol, nrow, byrow = FALSE)
invvech(x)

Arguments

x
vector or matrix
ncol,nrow
number of columns and rows for inverse of vech
byrow
flag for stacking row-wise or column-wise (default)

References

Magnus, J.R. & Neudecker H.M. (1999) Matrix Differential Calculus with Applications in Statistiscs and Econometrics (revised edition), Wiley & Sons. Chichester.

Examples

Run this code
x <- matrix(1:9, nrow=3, ncol=3)
y <- (x + t(x))/2
vec(x)
vech(y)
invvec(vec(x))
invvech(vech(y))

Run the code above in your browser using DataLab