statsmodels.stats.correlation_tools.corr_nearest(corr, threshold=1e-15, n_fact=100)
[source]
Find the nearest correlation matrix that is positive semi-definite.
The function iteratively adjust the correlation matrix by clipping the eigenvalues of a difference matrix. The diagonal elements are set to one.
Parameters: |
|
---|---|
Returns: |
corr_new – corrected correlation matrix |
Return type: |
ndarray, (optional) |
The smallest eigenvalue of the corrected correlation matrix is approximately equal to the threshold
. If the threshold=0, then the smallest eigenvalue of the correlation matrix might be negative, but zero within a numerical error, for example in the range of -1e-16.
Assumes input correlation matrix is symmetric.
Stops after the first step if correlation matrix is already positive semi-definite or positive definite, so that smallest eigenvalue is above threshold. In this case, the returned array is not the original, but is equal to it within numerical precision.
See also
© 2009–2012 Statsmodels Developers
© 2006–2008 Scipy Developers
© 2006 Jonathan E. Taylor
Licensed under the 3-clause BSD License.
http://www.statsmodels.org/stable/generated/statsmodels.stats.correlation_tools.corr_nearest.html