Skip to contents

This function samples a correlation matrix by sampling a covariance matrix from an inverse Wishart distribution and transforming it to a correlation matrix.

Usage

sample_correlation_matrix(dim, df = dim, scale = diag(dim))

Arguments

dim

[integer(1)]
The dimension.

df

[integer(1)]
The degrees of freedom of the inverse Wishart distribution greater or equal dim.

scale

[matrix()]
The scale covariance matrix of the inverse Wishart distribution of dimension dim.

Value

A correlation matrix.

Examples

sample_correlation_matrix(dim = 3)
#>            [,1]       [,2]       [,3]
#> [1,]  1.0000000 -0.7325002  0.8236824
#> [2,] -0.7325002  1.0000000 -0.9550453
#> [3,]  0.8236824 -0.9550453  1.0000000