# Generating a matrix so that correlations amongst columns are close to pre-defined values

I want to generate a matrix of values such that the correlations (e.g., Pearsons correlations) are close to a pre-defined set of values (e.g., corrs = [0.5, 0.7, -0.3, 0.9, 0.2]). For simplicity, we can assume we're only concerned with the correlation of pairs of columns.

For example, I may want a matrix with 4 columns and 100 rows, and the correlations between columns should be close to the following:

CORR(c1, c2) = corrs
CORR(c1, c3) = corrs
CORR(c1, c4) = corrs
CORR(c2, c3) = corrs
CORR(c2, c4) = corrs
CORR(c3, c4) = corrs


Depending on the parameters specified (matrix size, correlations), a solution may not exist, but for reasonable parameters, it seems like some algorithm should be able to come up with a solution.

Is there any areas of research that can help me accomplish this? It seems like something related to graphs and/or some iterative algorithm might be what I need, but I'm struggling with how to represent the problem mathematically or in a graph, and my knowledge of these areas is pretty limited.

• It seems like a multivariate normal distribution (or multivariate Student's $t$ distribution, if you like) checks these boxes. Are there any additional requirements? – Sycorax Jul 19 '17 at 15:48
• Thanks @Sycorax, that makes sense. I just adjust my covariance matrix accordingly. I'll try playing with this – Dolan Antenucci Jul 19 '17 at 15:52
• This might be what you're looking for econometricsbysimulation.com/2014/02/… – user5292 Jul 19 '17 at 18:55

## 1 Answer

Following @Sycorax's recommendation, I used a multivariate normal distribution to generate my desired dataset.

I set the means and variances for my columns to 0 and 1 respectively, thus the covariance matrix is populated with just the desired Pearson correlations (since cov(X,Y) = corr(X, Y) * std_dev_X * std_dev_Y).

Caveat to myself and others: Apparently the covariance matrix should be positive-semidefinite for proper sampling to occur, so the input set of correlations will need to be arranged or modified to create a positive-semidefinite covariance matrix.