Skip to contents

Generate a random variance-covariance matrix sampling the correlation values from a uniform distribution. The function does not guarantee that the matrix is positive definite. The variance is fixed to 1 for simulating standardized data.

Usage

gen_sigma(p, rmin, rmax = NULL)

Arguments

p

number of variables/indicators

rmin

minimum correlation

rmax

maximum correlation. Default to NULL. If NULL the minimum is used thus using a single value.

Value

a matrix

Examples

gen_sigma(3, 0.5) # compound symmetry
#>      [,1] [,2] [,3]
#> [1,]  1.0  0.5  0.5
#> [2,]  0.5  1.0  0.5
#> [3,]  0.5  0.5  1.0
gen_sigma(5, 0.5, 0.7)
#>           [,1]      [,2]      [,3]      [,4]      [,5]
#> [1,] 1.0000000 0.5161500 0.6668666 0.5314417 0.5995555
#> [2,] 0.5161500 1.0000000 0.6201522 0.5014799 0.5579534
#> [3,] 0.6668666 0.5014799 1.0000000 0.5932787 0.6465764
#> [4,] 0.6201522 0.5932787 0.5579534 1.0000000 0.6545043
#> [5,] 0.5314417 0.5995555 0.6465764 0.6545043 1.0000000