我正在解决简单的优化问题.数据集有26列和3000多个行. 源代码看起来像
I am solving simple optimization problem. The data set has 26 columns and over 3000 rows. The source code looks like
Means <- colMeans(Returns) Sigma <- cov(Returns) invSigma1 <- solve(Sigma)一切正常,但是我想在较短的时间内做同样的事情(仅261行),solve函数将写入以下错误:
And everything works perfect- but then I want to do the same for shorter period (only 261 rows) and the solve function writes the following error:
solve(Sigma) Error in solve.default(Sigma) : Lapack routine dgesv: system is exactly singular这很奇怪,因为当我用一些随机数进行相同操作时:
Its weird because when I do the same with some random numbers:
Returns<-matrix(runif(6786,-1,1), nrow=261) Means <- colMeans(Returns) Sigma <- cov(Returns) invSigma <- solve(Sigma)完全没有错误发生.有人可以向我解释问题可能在哪里以及如何解决. 非常感谢你, 亚历克斯
no error occurs at all. Could someone explain me where could be the problem and how to treat it. Thank you very much, Alex
推荐答案将solve与单个参数一起使用是对矩阵求逆的请求.错误消息告诉您矩阵是奇异的,无法反转.
Using solve with a single parameter is a request to invert a matrix. The error message is telling you that your matrix is singular and cannot be inverted.
更多推荐
R解决:系统完全是奇异的
发布评论