Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Let's say I want to generate correlated random variables. I understand that I can use Cholesky decomposition of the correlation matrix to obtain the correlated values. If $C$ is the correlation matrix, then we can do the cholesky decomposition:


Then I can easily generate correlated random variables:


where $X$ are uncorrelated values and $Y$ are correlated values. If I want two correlated random variables then $L$ is:

$L = \left[ {\begin{array}{*{20}c} 1 & 0 \\ \rho & {\sqrt {1 - \rho ^2 } } \\ \end{array}} \right] $

I understand that this works, but I don't really understand why... My question is: Why does this work?

share|cite|improve this question
up vote 25 down vote accepted

The co-variance matrix of any random vector $Y$ is given as $\mathbb{E} \left(YY^T \right)$, where $Y$ is a random column vector of size $n \times 1$. Now take a random vector, $X$, consisting of uncorrelated random variables with each random variable, $X_i$, having zero mean and unit variance $1$. Since $X_i$'s are uncorrelated random variables with zero mean and unit variance, we have $\mathbb{E} \left(X_iX_j\right) = \delta_{ij}$. Hence, $$\mathbb{E} \left( X X^T \right) = I$$ To generate a random vector with a given covariance matrix $Q$, look at the Cholesky decomposition of $Q$ i.e. $Q = LL^T$. Note that it is possible to obtain a Cholesky decomposition of $Q$ since by definition the co-variance matrix $Q$ is symmetric and positive definite.

Now look at the random vector $Z = LX$. We have $$\mathbb{E} \left(ZZ^T\right) = \mathbb{E} \left((LX)(LX)^T \right) = \underbrace{\mathbb{E} \left(LX X^T L^T\right) = L \mathbb{E} \left(XX^T \right) L^T}_{\text{ Since expectation is a linear operator}} = LIL^T = LL^T = Q$$ Hence, the random vector $Z$ has the desired co-variance matrix, $Q$.

share|cite|improve this answer
We're assuming here that ${\mathbb E}(X) = 0$. Otherwise the covariance matrix is ${\mathbb E}(X X^T) - ({\mathbb E} X)({\mathbb E} X^T)$. – Robert Israel Jun 26 '12 at 20:16
@RobertIsrael Yes. Thanks. I have updated it accordingly. – user17762 Jun 26 '12 at 20:17
But how do you specify whether the correlations of those variables are going to be positive or negative? – f1r3br4nd Jul 3 '14 at 12:23
So it should work for any decomposition of $Q=LL^T$, right? I mean, $L$ does not necessarily have to be triangular, as long as it satisfies that equation. Am I right? – Michael Apr 1 at 17:50

The specified correlation, C, can have negative element, i.e. Negative correlation. But, C, must Be positive definite to be a proper corr. matrix. E.g. [ 1 -0.9 0.5 -0.9 1 -0.1 0.5 -0.1 1 ] Is ok, but 0.9,-0.5,0.1 (in all places) produces a negative definite matrix, so not ok. Actually, for all values positive will have the effect that the sign of the second random variable changes.

share|cite|improve this answer

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.