R解决:系统完全是奇异的

编程入门 行业动态 更新时间:2024-10-24 02:38:52
本文介绍了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解决:系统完全是奇异的

本文发布于:2023-11-27 08:55:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1637382.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:奇异   系统

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!