# lower.tri elements (including diagonal) of a symmetric matrix
x <- c(4,1,5,2,3,6)
# reconstruct full symmetric matrix (row-wise!)
S <- lower2full(x)
# extract the same lower.tri elements again in the same order
vechr(S)
# without diagonal elements
vechr(S, diagonal=FALSE)
# duplication matrix
nvar <- ncol(S)
vec <- as.vector
Dup <- duplicationMatrix(nvar)
Dup %*% vech(S) == vec(S) # should all be true
# commutation matrix
K <- commutationMatrix(nvar, nvar)
K %*% vec(S) == vec(t(S)) # should all be true
# take sqrt root of a symmetric matrix
S.sqrt <- sqrtSymmetricMatrix(S)
S.sqrt %*% S.sqrt
# should be equal to S again (ignoring some rounding-off errors)
Run the code above in your browser using DataLab