vech2mat: Convert a half-vector (vech) into a matrix. In rockchalk: Regression Estimation and Presentation

Description

Fills a matrix from a vector that represents the lower triangle. If user does not supply a value for diag, then the vech will fill in the diagonal as well as the strictly lower triangle. If diag is provided (either a number or a vector), then vech is for the strictly lower triangular part. The default value for lowerOnly is FALSE, which means that a symmetric matrix will be created. See examples for a demonstration of how to fill in the lower triangle and leave the diagonal and the upper triangle empty.

Usage

 `1` ```vech2mat(vech, diag = NULL, lowerOnly = FALSE) ```

Arguments

 `vech` A vector `diag` Optional. A single value or a vector for the diagonal. A vech is a strictly lower triangluar vech, it does not include diagonal values. diag can be either a single value (to replace all elements along the diagonal) or a vector of the correct length to replace the diagonal. `lowerOnly` Default = FALSE.

Similar functions exist in many packages, see `vec2sm` in corpcor, `xpnd` in MCMCpack

Examples

 ```1 2 3 4 5``` ```x <- 1:6 vech2mat(x) vech2mat(x, diag = 7) vech2mat(x, diag = c(99, 98, 97, 96)) vech2mat(x, diag = 0, lowerOnly = TRUE) ```

Example output

```     [,1] [,2] [,3]
[1,]    1    2    3
[2,]    2    4    5
[3,]    3    5    6
[,1] [,2] [,3] [,4]
[1,]    7    1    2    3
[2,]    1    7    4    5
[3,]    2    4    7    6
[4,]    3    5    6    7
[,1] [,2] [,3] [,4]
[1,]   99    1    2    3
[2,]    1   98    4    5
[3,]    2    4   97    6
[4,]    3    5    6   96
[,1] [,2] [,3] [,4]
[1,]    0    0    0    0
[2,]    1    0    0    0
[3,]    2    4    0    0
[4,]    3    5    6    0
```

rockchalk documentation built on May 2, 2019, 5:09 a.m.