Article Menu |
Generating Correlated Random Numbersby M.A. (Thijs) van den Berg This article describes common methods that are used in generating correlated random numbers. [edit] Generating two sequences of correlated random numbersGenerating two sequences of random numbers with a given correlation is done in two simple steps:
This new [edit] Before and after correlating[edit] Generating multiple (more than two) sequences of correlated random variablesA general way to generate correlated (normal distributed) random numbers -with a given correlation matrix Using this matrix, one can generate correlated random numbers There are multiple way to find such a matrix. The two most common methods are
[edit] Example using a Cholesky decompositionWe want to generate random numbers for three variables with the following correlations matrix:
Doing a Cholesky decomposition on the correlation matrix give the following matrix:
Depending on the algorithm used for the Cholesky decomposition, you can also get the transposed of this matrix. This does doesn't matter. We can now transform three uncorrelated random numbers
into correlated numbers Rc by multiplying them with the U matrix.
[edit] Example using a Eigenvector decompositionThe correlation matrix and eigenvalues
If we define we get a matrix which gives us the final result for the decomposition
We can now transform three uncorrelated random numbers into correlated numbers Rc by multiplying them with the U matrix.
[edit] Example Matlab codeThe matlab code below decomposes the correlation matrix C into an upper matrix U using a Cholesky decomposition. Next 10 vectors with 3 random normal numbers are multiplied with the upper matrix to generate 10 correlated draws.
[edit] Comments
[edit] correlman said ...[edit] Jos said ...Great! Would be nice to have an additional page on fixing invalid correlation matrices. --Jos 11:36, 4 May 2007 (CEST) [edit] maquiavelo said ...Superb! Finally a clear explanation after googling in vain a hundred other articles. --maquiavelo 18:13, 20 May 2007 (CEST) [edit] Denisa said ...I really hope this is the answer for all my work till now ,because i needed such an algorithm to simulate fast fading :) --Denisa 18:35, 29 May 2007 (CEST) [edit] Pepe said ...Clear, concise, has examples - what to need more? Thumbs up! --Pepe 12:29, 30 May 2007 (CEST) [edit] harry said ...Amazing n cool . I can't believe its soo.. easy Finally a relief from useless notation found elsewhere.......... --harry 03:34, 16 June 2007 (CEST) [edit] Borat said ...Very Nice --Borat 16:07, 14 August 2007 (CEST) [edit] Zhang said ...Good job! --Zhang 19:10, 17 August 2007 (CEST) [edit] Rama said ...thanks..it is great help for me :) --Rama 10:47, 19 August 2007 (CEST) [edit] fnord said ...How do you extend the method to the case where one or more of the cross-correlations are negative? --fnord 17:22, 7 September 2007 (CEST) [edit] sitmo said ...Negative correlations is not different. The Cholesky decomposition of C to get U will also work with negative correlations (as long as the correlation matrix is 'valid/positive definite') --sitmo 09:45, 12 September 2007 (CEST) [edit] sw3quant said ...I used this for Monte Carlo, but needed to modify it. I used the covar matrix (not the corellMatrix). Multiply by the transpose of Q, not by Q. we checked through this at work using R and generating a vector of 1M gaussian variables. We used teh MAPCK implementation in C# which is pretty good. --sw3quant 11:18, 12 October 2007 (CEST) [edit] Tolga said ...my understanding is that, in both methods, we could really have used ANY orthogonal matrix U for the right-multiplications. After all, the correlations of the correlated random variables that are produced are actually given in the components of the orthonormal eigenvectors, not by the elements of the initial symmetric correlation matrix that yield those orthonormal eigenvectors. Am i right?? But if so, then what is the point of starting out with a correlation matrix? I am also wondering why/whether it is necessary for the squares of the correlations to add up to 1 when combining the uncorrelated random sequences to produce the correlated ones.
[edit] Ricardo said ...First of all, thank you for this straight foward solution. I need something quite similar, but with log-normal random variables. My idea is to generate N(0,1) corralated variables and then "transform" them to LN (miu,sigma) correlated variables. The theory presented remains valid? Thank you! --Ricardo 14:39, 10 January 2008 (CET) [edit] admin said ...Ricardo, Yes is does. If you take Y=exp( N(0,1) ) then Y is lognormal distributes and will take values between 0 and +infinity
[edit] chakazoulou said ...this correlation don't give rho --chakazoulou 11:49, 29 March 2008 (CET) [edit] chakazoulou said ...except if var(X1) = 1 = Var(x2) --chakazoulou 13:16, 29 March 2008 (CET) [edit] Sofia said ...Thank you admin for your very useful solution. I have a question. Does this formula apply to exponentially distributed variables as well? That is, if X1 and X2 are exp. distr. variables, then Y1 is correlated with X1 with coefficient rho? Thanks again! --Sofia 11:01, 6 May 2008 (CEST) [edit] Ricardo said ...Can you add a section on how to do this when the correlation matrix has complex values instead of all real? Thanks.
[edit] Rob said ...Great. Please your help on how to generate multiple sequences of correlated random vaiables not normally distributed for instance Gamma distribed? --Rob 05:56, 15 May 2008 (CEST) |
sequence will have a correlation of
with the
sequence.


- is done by finding a matrix U such that
from uncorrelated numbers
by multiplying them with this matrix.
that has the property
Thanks, excellent!
--correlman 11:19, 4 May 2007 (CEST)