Sign up ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

Let's assume I want to generate k samples of n random numbers, that are correlated according to a given correlation matrix C (e.g. $n = 3$):

1    0.3  0.3
0.3    1  0.3
0.3  0.3    1

Using Cholesky Decomposition (Python implementation from NumPy), I can calculate L so $C = LL^T$:

L = [[ 1.          0.          0.        ]
     [ 0.3         0.9539392   0.        ]
     [ 0.3         0.22013982  0.92819096]]

Generating n (uncorrelated) random numbers (using numpy.random.normal($\mu$, $\sigma$)) and multiplying each the vector with L should result in one sample with n correlated random variables. – So far my understanding of the algorithm.

When I check the random numbers with SPSS, the "observed" correlations differ from the ones given in C. Example: I choose $n = 3$, $k = 10 000$ and $r = 0.99$. The observed correlations are:

     V1        V2        V3
V1     1          .774      .578
V2      .774     1          .443
V3      .578      .443     1

For my use-case I will need random numbers, that represent the given correlation matrix precisely. Did I make a mistake in this process or did I misunderstand the algorithm? Some insight is much appreciated.

share|cite|improve this question
I found my mistake: I calculated $R_c = L \cdot R$ which is valid as long as $L$ is the upper triangle. As you can see in my question, my algorithm produces the lower triangle, i.e. $L^T$. I just had to change my code and either reverse the order of my multiplication ($R_c = R \cdot L^T$) or transpose the algorithm's result ($R_c = (L^T)^T \cdot R = L \cdot R$). Now, my observed correlations are close enough to the specified. –  neurotroph Apr 1 '14 at 17:59

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.