Czy przykładowa macierz kowariancji jest zawsze symetryczna i dodatnia?


33

Czy przy obliczaniu macierzy kowariancji próbki można uzyskać macierz symetryczną i dodatnią?

Obecnie mój problem obejmuje próbkę 4600 wektorów obserwacyjnych i 24 wymiary.


Do próbkowania macierzy kowariancji używam wzoru: Qn=1ni=1n(xix¯)(xix¯)gdzienjest liczbą próbek, ax¯ jest średnią próbki.
Morten

4
Można to normalnie nazwać „obliczaniem macierzy kowariancji próbki” lub „szacowaniem macierzy kowariancji” zamiast „próbkowaniem macierzy kowariancji”.
Glen_b

1
Częstą sytuacją, w której macierz kowariancji nie jest określona, ​​jest sytuacja, gdy 24 „wymiary” rejestrują skład mieszaniny, którego suma wynosi 100%.
whuber

Odpowiedzi:


41

Dla próbki wektorów xi=(xi1,,xik) , przy i=1,,n , średni wektor próbki wynosi

x¯=1ni=1nxi,
a macierz kowariancji próbki wynosi
Q=1ni=1n(xix¯)(xix¯).
Dla niezerowego wektorayRk mamy
yQy=y(1ni=1n(xix¯)(xix¯))y
=1ni=1ny(xix¯)(xix¯)y
=1ni=1n((xix¯)y)20.()
DlategoQ jest zawsze dodatnimpółokreślonym.

The additional condition for Q to be positive definite was given in whuber's comment bellow. It goes as follows.

Zdefiniuj zi=(xix¯) , dla i=1,,n . Dla każdego niezerowego yRk , () wynosi zero wtedy i tylko wtedy, gdy ziy=0 , dla każdego i=1,,n . Załóżmy, że zestaw {z1,,zn} obejmuje Rk . Następnie istnieją liczby rzeczywisteα1,,αn takie, żey=α1z1++αnzn . Ale wtedy mamyyy=α1z1y++αnzny=0 , co daje, żey=0 , sprzeczność. Stąd, jeślirozpiętośćziRk, then Q is positive definite. This condition is equivalent to rank[z1zn]=k.


2
I like this approach, but would advise some care: Q is not necessarily positive definite. The (necessary and sufficient) conditions for it to be so are described in my comment to Konstantin's answer.
whuber

1
Since the rank of [z1,z2,,zn] is less or equal to k, the condition can be simplified to the rank is equal to k.
an offer can't refuse

13

A correct covariance matrix is always symmetric and positive *semi*definite.

The covariance between two variables is defied as σ(x,y)=E[(xE(x))(yE(y))].

This equation doesn't change if you switch the positions of x and y. Hence the matrix has to be symmetric.

It also has to be positive *semi-*definite because:

You can always find a transformation of your variables in a way that the covariance-matrix becomes diagonal. On the diagonal, you find the variances of your transformed variables which are either zero or positive, it is easy to see that this makes the transformed matrix positive semidefinite. However, since the definition of definity is transformation-invariant, it follows that the covariance-matrix is positive semidefinite in any chosen coordinate system.

When you estimate your covariance matrix (that is, when you calculate your sample covariance) with the formula you stated above, it will obv. still be symmetric. It also has to be positive semidefinite (I think), because for each sample, the pdf that gives each sample point equal probability has the sample covariance as its covariance (somebody please verify this), so everything stated above still applies.


1
PS: I am starting to think that this wasn't your question...
Konstantin Schubert

But if you want to know whether your sampling algorithm guarantees it, you will have to state how you are sampling.
Konstantin Schubert

1
uQnu0uQn1/nvivivi=xix¯), whence nuQnu is a sum of u(vivi)u = (uvi)(uvi), which is the squared length of the vector uvi. Because n>0 and a sum of squares cannot ever be negative, uQnu0, QED. This also shows that uQnu=0 precisely for those vectors u which are orthogonal to all the vi (i.e., uvi=0 for all i). When the vi span, then u=0 and Qn is definite.
whuber

1
@Morten The transformation-invariance is pretty clear if you understand a matrix multiplication geometrically. Think of your vector as an arrow. The numbers that describe your vector change with the coordinate system, but the direction and length of your vector doesnt. Now, a multiplication with a matrix means that you change length and direction of that arrow, but again the effect is geometrically the same in each coordinate system. The same is with a scalar product: It is defined geometrically and Geometriy is transformation-invariant. So your equation has the same result in all systems.
Konstantin Schubert

1
@Morten When you think in coordinates, the argument goes like this: When A is your transformation matrix then: v=Av with v as the transformed coordinate-vector, M=AMAT, so when you transform each element in the equation vTMv>0, you get vTMv=(Av)TAMATAv>0, which equals vTATAMATAv>0, and, because A is orthogonal, ATA is the unit matrix and we again get vTMv>0, which means that the transformed and the untransformed equation have the same scalar as result, so their are either both or both not greater zero.
Konstantin Schubert

0

Variance-Covariance matrices are always symmetric, as it can be proven from the actual equation to calculate each term of said matrix.

Also, Variance-Covariance matrices are always square matrices of size n, where n is the number of variables in your experiment.

Eigenvectors of symmetric matrices are always orthogonal.

With PCA, you determine the eigenvalues of the matrix to see if you could reduce the number of variables used in your experiment.


1
Welcome Gen. Note that your username, identicon, & a link to your user page are automatically added to every post you make, so there is no need to sign your posts.
Antoine Vernet

3
This answer could be improved by addressing the issue of positive definiteness
Silverfish

This doesn't really answer the question: it's just a collection of unsupported assertions that might or might not be relevant. Could you reframe it in a way that shows how the question is answered and explains the reasoning?
whuber

0

I would add to the nice argument of Zen the following which explains why we often say that the covariance matrix is positive definite if n1k.

If x1,x2,...,xn are a random sample of a continuous probability distribution then x1,x2,...,xn are almost surely (in the probability theory sense) linearly independent. Now, z1,z2,...,zn are not linearly independent because i=1nzi=0, but because of x1,x2,...,xn being a.s. linearly independent, z1,z2,...,zn a.s. span Rn1. If n1k, they also span Rk.

To conclude, if x1,x2,...,xn are a random sample of a continuous probability distribution and n1k, the covariance matrix is positive definite.


0

For those with a non-mathematical background like me who don't quickly catch the abstract mathematical formulae, this is a worked out example excel for the most upvoted answer. The covariance matrix can be derived in other ways also.

enter image description here

enter image description here


Could you explain how this spreadsheet demonstrates positive-definiteness of the covariance matrix?
whuber

It does not. I had a hard time visualizing the covariance matrix in its notational form itself. So i created this sheet for myself and thought it could help someone.
Parikshit Bhinde

Please, then, edit it to include an answer to the question.
whuber

Done :) Thanks for suggesting.
Parikshit Bhinde

The question is "is one then guaranteed to get a symmetric and positive-definite matrix?" I am unable to perceive any element of your post that addresses this, because (1) it never identifies a covariance matrix; (2) it does not demonstrate positive-definiteness of anything.
whuber
Korzystając z naszej strony potwierdzasz, że przeczytałeś(-aś) i rozumiesz nasze zasady używania plików cookie i zasady ochrony prywatności.
Licensed under cc by-sa 3.0 with attribution required.