Make Sample Covariance/Correlation Matrix Positive Definite

I provide sample correlation matrix in copularnd() but I get error saying it should be positive definite. 
How to make my non-positive sample correlation matrix positive definite?

 채택된 답변

MathWorks Support Team
MathWorks Support Team 2021년 3월 8일
편집: MathWorks Support Team 2021년 3월 5일
The fastest way for you to check if your matrix "A" is positive definite (PD) is to check if you can calculate the Cholesky decomposition (A = L*L') of it. You can calculate the Cholesky decomposition by using the command "chol(...)", in particular if you use the syntax :
[L,p] = chol(A,'lower');
you get a lower trianglular matrix "L"; if the decomposition exists (your matrix is PD) "p" will equal 0. If "A" is not positive definite, then "p" is a positive integer. For more details about this please refer to documentation page:
Sample covariance and correlation matrices are by definition positive semi-definite (PSD), not PD. Semi-positive definiteness occurs because you have some eigenvalues of your matrix being zero (positive definiteness guarantees all your eigenvalues are positive). If you correlation matrix is not PD ("p" does not equal to zero) means that most probably have collinearities between the columns of your correlation matrix, those collinearities materializing in zero eigenvalues and causing issues with any functions that expect a PD matrix.
To fix this the easiest way will be to do calculate the eigen-decomposition of your matrix and set the "problematic/close to zero" eigenvalues to a fixed non-zero "small" value. That can be easily achieved by the following code, given your initial correlation matrix "A":
[V,D] = eig(A); % Calculate the eigendecomposition of your matrix (A = V*D*V') % where "D" is a diagonal matrix holding the eigenvalues of your matrix "A"d= diag(D); % Get the eigenvalues in a vector "d" d(d <= 1e-7) = 1e-7; % Set any eigenvalues that are lower than threshold "TH" ("TH" here being % equal to 1e-7) to a fixed non-zero "small" value (here assumed equal to 1e-7)D_c = diag(d); % Built the "corrected" diagonal matrix "D_c"A_PD = V*D_c*V'; % Recalculate your matrix "A" in its PD variant "A_PD"
Take note that due to issues of numeric precision you might have extremely small negative eigenvalues, when you eigen-decompose a large covariance/correlation matrix. These extremely small negative eigenvalues are "machine zeros". The work-around present above will also take care of them.
This work-around does not take care of the conditioning number issues; it does reduces it but not substantially. Additionally the Frobenius norm between matrices "A_PD" and "A" is not guaranteed to be the minimum. A more mathematically involved solution is available in the reference: "Nicholas J. Higham - Computing the nearest correlation matrix - a problem from finance", IMA Journal of Numerical Analysis Volume 22, Issue 3, p. 329-343 (pre-print available here: http://eprints.ma.man.ac.uk/232/01/covered/MIMS_ep2006_70.pdf )
 

댓글 수: 1

John D'Errico
John D'Errico 2017년 1월 12일
편집: John D'Errico 2017년 1월 12일
Note that my submission on the file exchange: nearestSPD does all of this for you, using the Higham algorithm, then finally ensuring the result is indeed SPD using the chol test.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Linear Algebra에 대해 자세히 알아보기

제품

릴리스

R2013a

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by