Package for the simulation of random correlation matrix
Implements several schemes to generate random correlation matrices, including
checks to validate a given matrix to be a proper correlation matrix.
Diagnostics contain two main methods - isPD and isvalid_corr. These methods
check for the following conditions in a given matrix -
import RandomCorrMatmatrix_to_test = [[1 , 0.9 , -0.9], [0.9, 1, 0.25], [-0.9, 0.25, 1]]res = RandomCorrMat.isvalid_corr(matrix_to_test)res == True # if the correlation is validres == False # if the correlation is invalid# To fetch more information in case the matrix is an invalid correlation matrix# we can use the followingres.cause
To generate random correlation matrix, there are several schemes:
import RandomCorrMatimport numpysize=10cor_value=0.5# Generate a constant correlation matrixRandomCorrMat.constantCorrMat(size, cor_value)# Generate a Random correalation matrix sampled uniformly from the space of corelation matricesRandomCorrMat.randCorrOnion(size)# Generate the Random correlation matrix, faster but no gauranteesRandomCorrMat.randCorr(size)# Generate a random correlation matrix with given eigenvaluese = numpy.r_[2, 1, 0.75, 0.25]corr_mat = RandomCorrMat.randCorrGivenEgienvalues(e)# Random perturbation of the correlation matrixgiven_corr_mat = numpy.array([[1, 0.5, 0.75],[0.5, 1, 0.75], [0.75, 0.75, 1]])new_corr = RandomCorrMat.perturb_randCorr(given_corr_mat)# Perturbation method can be used to generate correlation matrix with a given mean# For example: to generate a random correlation matrix with average corr = 0.75corr_mat = RandomCorrMat.constantCorrMat(4, 0.75)new_corr = RandomCorrMat.perturb_randCorr(corr_mat)# The variance of the perturbations obtained from the above method are not# sufficiently large, if we want to simulate random correlation with higher# variance or we need fine control on the noise added to the correlation matrix# Example to handle thesemanual_noisy_corr = given_corr_mat + numpy.random.normal(loc=0.0, scale=3.0, size=(3,3))valid_corr = RandomCorrMat.nearcorr(manual_noisy_corr)
Try
pip install RandCorrMat
To install manually from the git repo, try this:
python setup.py install
The RandCorrMat codebase supports Python 2 and 3.
If you happen to use RandCorrMat in your work or research, please cite its GitHub repository:
T. Roy, RandCorrMat, (2017), GitHub repository, https://github.com/tamaghnaroy/RandomCorrMat/
RandCorrMat is free software made available under the MIT License. For details see the LICENSE file.