1
votes

I'm trying to change a correlation matrix into co-variance matrix...

Importing some data, I found the co-variance (sigma_a)

sigma_a = (sigma_d + (mu_d'+1)*(mu_d+1)).^N - (mu_d'+1).^N *(mu_d+1).^N;

Which returns...

0.1211    0.0231    0.0422    0.0278    0.0411    0.0354    0.0289    0.0366    0.0343    0.0165
0.0231    0.0788    0.0283    0.0242    0.0199    0.0248    0.0219    0.0199    0.0253    0.0140
0.0422    0.0283    0.1282    0.0339    0.0432    0.0366    0.0321    0.0399    0.0420    0.0216
0.0278    0.0242    0.0339    0.0554    0.0261    0.0294    0.0312    0.0269    0.0297    0.0164
0.0411    0.0199    0.0432    0.0261    0.0849    0.0289    0.0271    0.0371    0.0317    0.0173
0.0354    0.0248    0.0366    0.0294    0.0289    0.0728    0.0293    0.0400    0.0339    0.0149
0.0289    0.0219    0.0321    0.0312    0.0271    0.0293    0.0454    0.0276    0.0309    0.0135
0.0366    0.0199    0.0399    0.0269    0.0371    0.0400    0.0276    0.0726    0.0356    0.0162
0.0343    0.0253    0.0420    0.0297    0.0317    0.0339    0.0309    0.0356    0.0715    0.0198
0.0165    0.0140    0.0216    0.0164    0.0173    0.0149    0.0135    0.0162    0.0198    0.0927

Then I found the correlation matrix (rho)

rho = inv(sqrt(diag(diag(sigma_a))))*sigma_a*inv(sqrt(diag(diag(sigma_a))));  

Which returns...

  1.0000    0.2365    0.3388    0.3396    0.4050    0.3772    0.3897    0.3899    0.3686    0.1556
  0.2365    1.0000    0.2812    0.3656    0.2437    0.3274    0.3658    0.2631    0.3377    0.1638
  0.3388    0.2812    1.0000    0.4027    0.4141    0.3792    0.4199    0.4133    0.4382    0.1985
  0.3396    0.3656    0.4027    1.0000    0.3809    0.4638    0.6221    0.4246    0.4728    0.2295
  0.4050    0.2437    0.4141    0.3809    1.0000    0.3681    0.4366    0.4732    0.4068    0.1948
  0.3772    0.3274    0.3792    0.4638    0.3681    1.0000    0.5093    0.5499    0.4707    0.1813
  0.3897    0.3658    0.4199    0.6221    0.4366    0.5093    1.0000    0.4797    0.5428    0.2079
  0.3899    0.2631    0.4133    0.4246    0.4732    0.5499    0.4797    1.0000    0.4936    0.1971
  0.3686    0.3377    0.4382    0.4728    0.4068    0.4707    0.5428    0.4936    1.0000    0.2435
  0.1556    0.1638    0.1985    0.2295    0.1948    0.1813    0.2079    0.1971    0.2435    1.0000

I know there is the function corrcov() in matlab that finds the correlation matrix... So I tried,

 corrcov(sigma_a) 

I compared the results and both corrcov(sigma_a) and rho produced the same correlation matrix. However then I wanted to change all of the pairwise correlations by exactly +0.1. Which I did, with

rho_u = (rho + .1) - .1*eye(10); 

And I got the following correlation matrix...

  1.0000    0.3365    0.4388    0.4396    0.5050    0.4772    0.4897    0.4899    0.4686    0.2556
  0.3365    1.0000    0.3812    0.4656    0.3437    0.4274    0.4658    0.3631    0.4377    0.2638
  0.4388    0.3812    1.0000    0.5027    0.5141    0.4792    0.5199    0.5133    0.5382    0.2985
  0.4396    0.4656    0.5027    1.0000    0.4809    0.5638    0.7221    0.5246    0.5728    0.3295
  0.5050    0.3437    0.5141    0.4809    1.0000    0.4681    0.5366    0.5732    0.5068    0.2948
  0.4772    0.4274    0.4792    0.5638    0.4681    1.0000    0.6093    0.6499    0.5707    0.2813
  0.4897    0.4658    0.5199    0.7221    0.5366    0.6093    1.0000    0.5797    0.6428    0.3079
  0.4899    0.3631    0.5133    0.5246    0.5732    0.6499    0.5797    1.0000    0.5936    0.2971
  0.4686    0.4377    0.5382    0.5728    0.5068    0.5707    0.6428    0.5936    1.0000    0.3435
  0.2556    0.2638    0.2985    0.3295    0.2948    0.2813    0.3079    0.2971    0.3435    1.0000

However, when I attempt to take the adjusted correlation matrix and make it a co-variance matrix the cov() is not producing the right matrix. I tried...

b = cov(rho_u);

Why is that? Is there another way to do that? Or is there a way to adjust what I did with

 rho = inv(sqrt(diag(diag(sigma_a))))*sigma_a*inv(sqrt(diag(diag(sigma_a)))); 

so that it does the opposite (rho found the correlation matrix) to get the co-varience matrix instead?

Based on my understanding from the answer below, then the co-variance matrix for rho_u would be achieved by, doing...

sigma = sqrt(var(rho_u));
D = diag(sigma); 
sigma_u = D*rho_u*D

Is this what was meant? I was little confused by which variables I should take the variance to. I thought that meant rho_u?

1
Consider marking the answers as accepted that solve your previous problems in your previous questions by clicking on the left of the answers. You can also upvote all the helpful answers by clicking on the left of the answers. This awards the volunteers the reward that they deserve and helps the future visitors to identify the usefulness of the answers. If those answers don't solve your problem, please comment under the answers to explain the problem/s to let the answerers know about that. ThanksSardar Usama

1 Answers

2
votes

The MATLAB function cov is not defined to transform a correlation matrix to covariance matrix, as its documentation says

cov(X), if X is a vector, returns the variance.  For matrices, where 
each row is an observation, and each column a variable, cov(X) is the 
covariance matrix.

So simply feeding the correlation matrix to cov() won't work. What you need to calculate the covariance matrix is the variance of your variables (which you can calculate from your data, but didn't post here)

So in your example using the 10x10 correlation matrix rho you posted and using some random numbers for the the standard deviations

sigma = rand(size(rho(:,1)));
D = diag(sigma);         % Make the sigmas appear on the diagonal of an 10x10 matrix

(you have to insert the calculated values from your input data, of course). You can then calculate the covariance matrix by

S = D*rho*D