Learn R Programming

randcorr (version 1.0)

randcorr: Generate a random p x p correlation matrix

Description

Generate a random p x p correlation matrix

Usage

randcorr(p)

Arguments

p

A scalar positive integer denoting the size of the correlation matrix

Value

A random p x p correlation matrix

Details

This function implements the algorithm by Pourahmadi and Wang [1] for generating a random p x p correlation matrix. Briefly, the idea is to represent the correlation matrix using Cholesky factorization and p(p-1)/2 hyperspherical coordinates (i.e., angles), sample the angles form a particular distribution and then convert to the standard correlation matrix form. The angles are sampled from a distribution with probability density function sin^k(theta) (0 < theta < pi, k >= 1) using the efficient sampling algorithm described in [2].

References

[1] Mohsen Pourahmadi and Xiao Wang, Distribution of random correlation matrices: Hyperspherical parameterization of the Cholesky factor, Statistics & Probability Letters, Volume 106, Pages 5-12, 2015.

[2] Enes Makalic and Daniel F. Schmidt An efficient algorithm for sampling from sin^k(x) for generating random correlation matrices, arXiv:1809.05212, 2018.

See Also

randcorr.sample.sink

Examples

Run this code
# NOT RUN {
# -----------------------------------------------------------------
# Example 1: Generate a 5x5 correlation matrix
C = randcorr(5)

# Example 2: Generate a 1000x1000 correlation matrix
C = randcorr(1000)



# }

Run the code above in your browser using DataLab