How to calculate correlation matrix

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>^ $. So, if you start with data that has mean zero, multiplying by $<\bf A>$ will not change that, so your first requirement is easily satisfied.

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 1 & .8 & 0 \\ .8 & 1 & .8 \\ 0 & .8 & 1 \\ \end \right) $$

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 1 & .8 & .3 \\ .8 & 1 & .8 \\ .3 & .8 & 1 \\ \end \right) \ \ \ \ <\rm or> \ \ \ \Omega = \left( \begin 1 & 2/3 & 0 \\ 2/3 & 1 & 2/3 \\ 0 & 2/3 & 1 \\ \end \right)$$

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 1 & 0 & 0 \\ .8 & .6 & 0 \\ .3 & .933 & .1972 \\ \end \right) \ \ \ \ <\rm or> \ \ \ <\bf A> = \left( \begin 1 & 0 & 0 \\ 2/3 & .7453 & 0 \\ 0 & .8944 & .4472 \\ \end \right)$$

The R code used to arrive at this was:

http://stats.stackexchange.com/questions/32169/how-can-i-generate-data-with-a-prespecified-correlation-matrix how to calculate correlation matrix

Source: stats.stackexchange.com

Category: Forex

Similar articles: