# How to define a covariance matrix that is positive semi definite?

1 ビュー (過去 30 日間)
Niveditha Kumar 2019 年 9 月 30 日

mu = [80 130 200];
sigma = [1 1.5 4; 1.5 3 2; 4 2 1];
rng('default') % For reproducibility
R = mvnrnd(mu,sigma,200);

#### 0 件のコメント

サインイン to comment.

### 回答 (2 件)

the cyclist 2019 年 9 月 30 日

First, let me explain why sigma has to be positive semidefinite.
Take this correlation matrix as an example:
sigma = [1.0 0.9 0.9;
0.9 1.0 0.2;
0.9 0.2 1.0];
Imagine that this represents the correlation of the stock prices of three companies: A, B, and C (corresponding to the 1st, 2nd, and 3rd columns, respectively).
Notice that companies A and B are correlated at 0.9 -- their stocks prices are very highly correlated. Similarly, companies A and C are very highly correlated.
From those two facts, we can see that companies B and C must also be pretty highly correlated. If A and B move together, and A and C move together, then B and C must move together.
But, according to this matrix, B and C are only correlated 0.2. This is not possible. There is an inconsistency among these correlation coefficients!
That inconsistency is why this matrix is not positive semidefinite, and why it is not possible to simulate correlated values based on this matrix.
===
Now, to your question. Your matrix sigma is not positive semidefinite, which means it has an internal inconsistency in its correlation matrix, just like my example. It's not always easy to see exactly why.
It is also not clear how to fix it, while still solving the problem you want to solve.
If you simply want to generate a matrix that will work, then you can take any real-valued matrix M, and do the following:
sigma = M'*M;
sigma is guaranteed to be positive semidefinite in this case.
But if the sigma you used is actually supposed to be meaningful for some reason, then you need to figure out why it is invalid.
I hope that helps!

#### 0 件のコメント

サインイン to comment.

Bruno Luong 2019 年 9 月 30 日
L=randn(3);
sigma=L'*L

#### 0 件のコメント

サインイン to comment.

サインイン してこの質問に回答します。