# How to calculate correlation matrix

It appears that you're asking how to generate data with a particular correlation matrix.

A useful fact is that if you have a random vector $<\bf x>$ with covariance matrix $\Sigma$, then the random vector $<\bf Ax>$ has mean $<\bf A> E(<\bf x>)$ and covariance matrix $ \Omega = <\bf A> \Sigma <\bf A>^

Let's say you start with (mean zero) uncorrelated data (i.e. the covariance matrix is diagonal) - since we're talking about the correlation matrix, let's just take $\Sigma = I$. You can transform this to data with a given covariance matrix by choosing $<\bf A>$ to be the cholesky square root of $\Omega$ - then $<\bf Ax>$ would have the desired covariance matrix $\Omega$.

In your example, you appear to want something like this:

$$ \Omega = \left( \begin

Unfortunately that matrix is not positive definite, so it cannot be a covariance matrix - you can check this by

seeing that the determinant is negative. Perhaps, instead

$$ \Omega = \left( \begin

would suffice. I'm not sure how to calculate the cholesky square root in matlab (which appears to be what you're using) but in R you can use the chol() function.

In this example, for the two $\Omega$s listed above the proper matrix multiples(respectively) would be

$$ <\bf A> = \left( \begin

The R code used to arrive at this was: