comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Covariance Matrix
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Covariance Matrix [message #86849 is a reply to message #86847] Sat, 07 December 2013 06:37 Go to previous messageGo to previous message
amin farhang is currently offline  amin farhang
Messages: 39
Registered: November 2010
Member
Hi David,

Indeed there is no any B vector in my problem. In statistical notes, for computing the covariance of a vector the following formula can be used:
cov(A,A) = E[(A-EA)*(A-EA)^T]
where E means expected value, EA is the mean value of A vector and T means transpose of A vector. I write a code for this (A is a column vector):

s = size(A)
Na = s[2]
MeanValue = total(A)/float(Na)
AT = transpose(A)
A = A - MeanValue
AT = AT - MeanValue
covariance = A ## AT

for example for A=[1,2,3,4] the covariance matrix with above code become:

2.25000 0.750000 -0.750000 -2.25000
0.750000 0.250000 -0.250000 -0.750000
-0.750000 -0.250000 0.250000 0.750000
-2.25000 -0.750000 0.750000 2.25000

but the weird thing is that if we divide the covariance matrix by standard deviation of A and AT we should see the correlation matrix.
in above example std(A) = 1.29 so correlation(A) = COV(A)/(std * std):

1.74419 0.581395 -0.581395 -1.74419
0.581395 0.193798 -0.193798 -0.581395
-0.581395 -0.193798 0.193798 0.581395
-1.74419 -0.581395 0.581395 1.74419

but we know that the correlation coefficients must be between -1 and 1 (diagonal elements must be equal to 1) but you see that in addition to being 1 in diagonal, the off-diagonal are greater than 1 in some cases!!

what is happening? how can I compute correct covariance that with conversion to correlation matrix all elements be in correct range?

or is it a code in IDL for computing the correlation matrix of vector?

Thanks,
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Array -Time
Next Topic: Zooming in function graphics

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Oct 10 01:42:58 PDT 2025

Total time taken to generate the page: 1.03933 seconds