Skip to contents

vech2Corr is a convenience function for creating correlation matrices from a vector of the lower triangular values. It checks the arguments to make sure they are consistent with the requirements of a correlation matrix. All values must be in [-1, 1], and the number of values specified must be correct for a lower triangle.

Usage

vech2Corr(vech)

Arguments

vech

A vector of values for the strictly lower triangle of a matrix. All values must be in the [0,1] interval (because they are correlations) and the matrix formed must be positive definite.

Value

A symmetric correlation matrix, with 1's on the diagonal.

Details

Use this in combination with the lazyCov function to convert a vector of standard deviations and the correlation matrix into a covariance matrix.

See also

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

Author

Paul E. Johnson pauljohn@ku.edu

Examples

v <- c(0.1, 0.4, -0.5)
vech2Corr(v)
#>      [,1] [,2] [,3]
#> [1,]  1.0  0.1  0.4
#> [2,]  0.1  1.0 -0.5
#> [3,]  0.4 -0.5  1.0
v <- c(0.1, 0.4, -0.4, 0.4, 0.5, 0.1)
vech2Corr(v)
#>      [,1] [,2] [,3] [,4]
#> [1,]  1.0  0.1  0.4 -0.4
#> [2,]  0.1  1.0  0.4  0.5
#> [3,]  0.4  0.4  1.0  0.1
#> [4,] -0.4  0.5  0.1  1.0