Create a correlation matrix

genCorMat(nvars, cors = NULL)

## Arguments

nvars number of rows and columns (i.e. number of variables) for correlation matrix vector of correlations.

## Value

correlation matrix of size nvars x nvars

## Details

If the vector cors is not specified, a random correlation matrix is generated with no assumptions. If the vector is provided, it should be interpreted as the lower triangle of the correlation matrix, and is specified by reading down the columns. For example, if CM is the correlation matrix and nvars = 3, then CM[2,1] = cors[1], CM[3,1] = cors[2], and CM[3,2] = cors[3].

## Examples

genCorMat(3, c(.3, -.2, .1))
#>      [,1] [,2] [,3]
#> [1,]  1.0  0.3 -0.2
#> [2,]  0.3  1.0  0.1
#> [3,] -0.2  0.1  1.0genCorMat(3)
#>            [,1]        [,2]        [,3]
#> [1,]  1.0000000 -0.05721830 -0.26562439
#> [2,] -0.0572183  1.00000000 -0.08206648
#> [3,] -0.2656244 -0.08206648  1.00000000
genCorMat(5, c(.3, -.2, .1, .2, .5, .2, -.1, .3, .1, .2))
#>      [,1] [,2] [,3] [,4] [,5]
#> [1,]  1.0  0.3 -0.2  0.1  0.2
#> [2,]  0.3  1.0  0.5  0.2 -0.1
#> [3,] -0.2  0.5  1.0  0.3  0.1
#> [4,]  0.1  0.2  0.3  1.0  0.2
#> [5,]  0.2 -0.1  0.1  0.2  1.0genCorMat(5)
#>             [,1]        [,2]        [,3]       [,4]        [,5]
#> [1,]  1.00000000  0.18378060 -0.08859631 0.07366686  0.04571161
#> [2,]  0.18378060  1.00000000  0.34041009 0.03797508 -0.48391898
#> [3,] -0.08859631  0.34041009  1.00000000 0.12364752  0.27887791
#> [4,]  0.07366686  0.03797508  0.12364752 1.00000000  0.32682135
#> [5,]  0.04571161 -0.48391898  0.27887791 0.32682135  1.00000000