R solve:system is exactly singular

后端 未结 3 822
再見小時候
再見小時候 2020-12-01 17:54

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           


        
相关标签:
3条回答
  • 2020-12-01 18:43

    I guess your code uses somewhere in the second case a singular matrix (i.e. not invertible), and the solve function needs to invert it. This has nothing to do with the size but with the fact that some of your vectors are (probably) colinear.

    0 讨论(0)
  • 2020-12-01 18:45

    Lapack is a Linear Algebra package which is used by R (actually it's used everywhere) underneath solve(), dgesv spits this kind of error when the matrix you passed as a parameter is singular.

    As an addendum: dgesv performs LU decomposition, which, when using your matrix, forces a division by 0, since this is ill-defined, it throws this error. This only happens when matrix is singular or when it's singular on your machine (due to approximation you can have a really small number be considered 0)

    I'd suggest you check its determinant if the matrix you're using contains mostly integers and is not big. If it's big, then take a look at this link.

    0 讨论(0)
  • 2020-12-01 18:54

    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.

    0 讨论(0)
提交回复
热议问题