vech {lazy.mat}R Documentation

Vectorization of the lower-half or upper-half of a square matrix

Description

Vectorization of the lower-half or upper-half of a square matrix

Usage

vech(S, nodiag = 0, byrow = 1, lowerh = 1)

Arguments

S

Input square matrix or array whose lower or upper half elements will be vectorized.

nodiag

= 1 to omit the diagonal elements

byrow

= 0 to vectorize in col-major order

lowerh

= 0 to vectorize upper-half

Details

Let M be 4 x 4.
When byrow=1 and lowerh=1,

vech(M)=c( m11, m21, m22, m31, m32, m33, ..., mn1, mn2, ..., mnn )

When byrow=1 and lowerh=0,

vech(M)=c( m11, m12, m13, ..., m1n, m22, m23, m24, ..., m2n, ..., mnn )

When byrow=0 and lowerh=1, the upper half of the matrix will be vectorized in row major order as:

vech(M)=c( m11, m21, m31, ..., mn1, m22, m32, ..., mn2, m33, ...., mnn )

When byrow=0 and lowerh=0, the upper half of the matrix will be vectorized in row major order as:

vech(M)=c( m11, m12, m22, m13, m23, m33, m14, ..., m44, m1n, m2n, ...., mnn )


Note that vech(M,lowerh=0) and vech(t(M),lowerh=1) are the same except for their row names.

Use vechinv to recover the original matrix.

Value

A column vector when S is a matrix, or a matrix when S is an array.

Examples

ndim=5
M=demomat(ndim,ndim,root="m")
cat("nodiag=0:  byrow=1, lowwer=1  and  byrow=0, lowwer=1")
Print(vech(M,0,1,1),vech(M,0,0,1))
cat("nodiag=0:  byrow=1, lowwer=0  and  byrow=0, lowwer=0")
Print(vech(M,0,1,0),vech(M,0,0,0))

cat("nodiag=1:  byrow=1, lowwer=1  and  byrow=0, lowwer=1")
Print(vech(M,1,1,1),vech(M,1,0,1))
cat("nodiag=1:  byrow=1, lowwer=0  and  byrow=0, lowwer=0")
Print(vech(M,1,1,0),vech(M,1,0,0))

cat("Should be equal.")
Print(vech(M,lowerh=0), vech(t(M),byrow=0))

# converting to a native vector with name
vecM=vech(M)
vecM=vecM[,1,drop=1]


[Package lazy.mat version 0.1.3 Index]