Generates random correlation matrices from the LKJ (Lewandowski-Kurowicka-Joe) distribution. The LKJ distribution is a prior distribution over correlation matrices that generalizes the uniform distribution over correlation matrices. As eta increases, more probability mass is concentrated around the identity matrix.
Source
These functions come from Richard McElreath's rethinking package and, judging by the source code, it seems that he got them from Ben Goodrich.
Arguments
- n
Integer. Number of correlation matrices to generate
- K
Integer. Dimension of the correlation matrix (number of rows/columns). Must be at least 2
- eta
Numeric. Shape parameter controlling the concentration around the identity matrix. Must be positive. When eta = 1, the distribution is uniform over correlation matrices. As eta increases, more mass is placed on matrices closer to the identity matrix
Value
If n = 1, returns a single K×K correlation matrix.
If n > 1, returns a list of n correlation matrices.
All matrices are symmetric and positive definite with 1s on the diagonal.
References
Lewandowski, D., Kurowicka, D., & Joe, H. (2009). Generating random correlation matrices based on vines and extended onion method. Journal of multivariate analysis, 100(9), 1989-2001.
Examples
# Generate a single 4x4 correlation matrix
rho1 <- rlkjcorr(n = 1, K = 4, eta = 1)
round(rho1, 2)
#> [,1] [,2] [,3] [,4]
#> [1,] 1.00 -0.24 -0.37 -0.48
#> [2,] -0.24 1.00 0.80 0.15
#> [3,] -0.37 0.80 1.00 0.33
#> [4,] -0.48 0.15 0.33 1.00
# Generate 5 correlation matrices with more concentration around identity
rho_list <- rlkjcorr(n = 5, K = 3, eta = 4)
lapply(rho_list, round, 2)
#> [[1]]
#> [,1] [,2] [,3]
#> [1,] 1.00 0.39 0.21
#> [2,] 0.39 1.00 0.16
#> [3,] 0.21 0.16 1.00
#>
#> [[2]]
#> [,1] [,2] [,3]
#> [1,] 1.00 -0.66 0.44
#> [2,] -0.66 1.00 -0.24
#> [3,] 0.44 -0.24 1.00
#>
#> [[3]]
#> [,1] [,2] [,3]
#> [1,] 1.00 -0.37 0.32
#> [2,] -0.37 1.00 0.11
#> [3,] 0.32 0.11 1.00
#>
#> [[4]]
#> [,1] [,2] [,3]
#> [1,] 1.00 0.05 -0.17
#> [2,] 0.05 1.00 0.06
#> [3,] -0.17 0.06 1.00
#>
#> [[5]]
#> [,1] [,2] [,3]
#> [1,] 1.00 0.01 0.40
#> [2,] 0.01 1.00 -0.31
#> [3,] 0.40 -0.31 1.00
#>