协方差矩阵的特征值中的一个是R中负(one of Eigenvalues of covariance

2019-10-22 15:13发布

我有一个数据集x 。 我用cov(x)来计算的协方差x 。 我想要计算的倒数平方根cov(x) 。 但我得到的负本征值cov(x)

这里是我的代码

S11=cov(x)
S=eigen(S11,symmetric=TRUE)
R=solve(S$vectors %*% diag(sqrt(S$values)) %*% t(S$vectors))

这是特征值S

c(0.897249923338732, 0.814314811717616, 0.437109871173458, 0.334921280373883, 
0.291910583884559, 0.257388456770167, 0.166787180227719, 0.148268784967556, 
0.121401731579852, 0.0588333377333529, 0.0519459283467876, 0.0472867806813002, 
0.0438199555429584, 0.0355421239839632, 0.0325106968911777, 0.0282860419784165, 
0.0222240269478354, 0.0174657163114068, 0.012318267910606, 0.00980611646284724, 
0.00969450391092417, 0.00804912897151307, 0.00788628666010145, 
0.00681419055130702, 0.00664707528670254, 0.00591471779140177, 
0.00581608875646686, 0.0057489828718098, 0.00564645095578336, 
0.00521029715741059, 0.00503304953884416, 0.0048677189522647, 
0.00395692706081966, 0.00391665618240403, 0.00389825739725093, 
0.00383611535401152, 0.00374242176786387, 0.0035160324422885, 
0.00299245160843966, 0.0029501156885799, 0.00289484923017341, 
0.00287327878694529, 0.0028447265712214, 0.00274130080219099, 
0.00273159993035393, 0.00265595612239575, 0.00261856622830277, 
0.0020004125628823, 0.00199834766485368, 0.00199579695856402, 
0.00198945452395265, 0.00197999810684363, 0.00195954105720554, 
0.00195502875017394, 0.00194143254092788, 0.00192530399875842, 
0.00191287435824908, 0.00187418676921454, 0.00184304720875652, 
0.00181132707713659, 0.00167004122321738, 0.00132136106130093, 
0.001001001001001, 0.001001001001001, 0.001001001001001, 0.00100089827907564, 
0.000999613336959707, 0.000999285885989665, 0.000995390174780253, 
0.000990809217795241, 0.000987333916025995, 0.000984260717691378, 
0.000982735942052615, 0.000971684328336702, 0.000964125499180901, 
0.000961900381008093, 0.000947883827257506, 0.000922293473088298, 
0.000862086463606162, 0.000829687294735196, 0.000732694198613695, 
1.95782839335209e-17, 4.13905030077713e-18, 2.02289095736911e-18, 
8.72989281345777e-19, 3.79161425300691e-19, -7.97468731082902e-20)

Answer 1:

虽然理论上估计协方差矩阵必须是正(半)确定的,即没有负值,在实践中的浮点错误可以违反此。 对我来说,毫无疑问,一个87分87矩阵可能有一个微小的负(约-1×10 ^( - 19))的特征值。

根据你想要做什么,你可以使用?nearPDMatrix封装强迫你的协方差矩阵是正定的:

计算最近的正定矩阵来近似一个,通常是相关性或方差 - 协方差矩阵。

此外,它可能会更有效地计算Cholesky分解( ?chol首先你的矩阵,然后倒转)(这是很容易原则-我认为你可以使用backsolve()



文章来源: one of Eigenvalues of covariance matrix is negative in R