File Exchange

image thumbnail

randcorr

version 1.1.1 (1.97 KB) by Statovic
This function implements the algorithm by Pourahmadi and Wang for generating a random p x p correlation matrix.

2 Downloads

Updated 21 Jan 2020

View Version History

View License

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, November 2015, Pages 5-12

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

Cite As

Statovic (2021). randcorr (https://www.mathworks.com/matlabcentral/fileexchange/68810-randcorr), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (2)

Statovic

Thanks Raffaele. The code has been updated to fix this numerical issue.

Raffaele Lacatena

There's an issue about diagonal elements of randcorr which should be all equal to 1 and often they're not.
This makes impossible to use randcorr output as an input of any matlab function which requires covariance matrix.

Bug can be easily fixed replacing diagonal elements of randcorr(n) with ones.

MATLAB Release Compatibility
Created with R2018b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Tags Add Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!