R解决:系统完全是奇异的 [英] R solve:system is exactly singular

查看:770
本文介绍了R解决:系统完全是奇异的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在解决简单的优化问题.数据集有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解决:系统完全是奇异的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆