Skip to main content

random_correlation_matrix

Function random_correlation_matrix 

Source
pub fn random_correlation_matrix<R: Rng + ?Sized>(
    dimension: usize,
    rng: &mut R,
) -> Result<DMatrix<f64>>
Expand description

Generate a random correlation matrix.

Uses the method of Joe (2006) to generate a random correlation matrix that is guaranteed to be positive definite.

§Arguments

  • dimension - Size of the correlation matrix
  • rng - Random number generator

§Returns

A random positive definite correlation matrix.

§Examples

use copula_core::random_correlation_matrix;
use rand::thread_rng;

let mut rng = thread_rng();
let corr = random_correlation_matrix(3, &mut rng).unwrap();