Description Usage Arguments Value Author(s) See Also Examples
The function vechMat
transforms a symmetric matrix in a vector containing its lower triangular elements, taken by column. The function xpndMat
reverses this transformation.
1 2 3 |
mat |
a square matrix. |
vech |
a vector. |
diag |
a logical switch indicating if the diagonal entries must be included. |
A vector for vechMat
, a symmetric matrix for xnpdMat
.
Antonio Gasparrini <antonio.gasparrini@lshtm.ac.uk>
See functions vech
and xpnd
in package MCMCpack.
1 2 3 4 5 6 7 8 9 | # GENERATE A POSITIVE-DEFINITE MATRIX, VECTORIZE IT AND THEN RE-EXPAND
(M <- crossprod(matrix(rnorm(9),3)))
(v <- vechMat(M))
xpndMat(v)
# EXTRACT VECTORIZED S, EXPAND TO A LIST, AND RE-VECTORIZE
(S <- as.matrix(berkey98[5:7]))
(Slist <- lapply(seq(nrow(S)), function(i) xpndMat(S[i,])))
t(sapply(Slist,vechMat))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.