[R] solve computationally singular

Simon Wood s.wood at bath.ac.uk
Thu Nov 9 16:49:59 CET 2006


On Tuesday 07 November 2006 19:46, xchen wrote:
> Hi uRsers,
>
> when inverting a 2 by 2 matrix using solve, I encountered a error message:
> solve.default(sigma, tol = 1e-07) :
>         system is computationally singular: reciprocal condition number
> = 1.7671e-017
>
> and then I test the determinant of this matrix: 6.341393e-06.
>
> In my program, I have a condition block that whether a matrix is
> invertible like this:
> if(det(sigma)<1e-7) return NULL;

- the determinant isn' t the best way of testing for computational 
singularity. 

For example, in the following `a' is computationally singular (it has a 
condition number of 1e18, but it has a determinant of 1e-6) 

a<- diag(c(1e6,1e-12)) 
> a
      [,1]  [,2]
[1,] 1e+06 0e+00
[2,] 0e+00 1e-12
> det(a)
[1] 1e-06
> solve(a)
Error in solve.default(a) : system is computationally singular: reciprocal 
condition number = 1e-18

If you are really only interested in small matrices, then calculation of the 
condition number as the ratio of largest to smallest singular values is the 
most reliable thing to do (or you could just trap the `solve' errors). See 
e.g. Golub and van Loan "Matrix Computations" for efficient condition number 
estimators, for larger matrices. 

Simon

>
> but this seems doesnot work to prevent the singularity when inverting a
> matrix. I am some confused about the relationship between "reciprocal
> condition number" and determinant. Can anybody give me some idea how to
> prevent this situation?
>
> Thanks a lot!
>
> Xiaohui
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html and provide commented, minimal,
> self-contained, reproducible code.

-- 
> Simon Wood, Mathematical Sciences, University of Bath, Bath, BA2 7AY UK
> +44 1225 386603  www.maths.bath.ac.uk/~sw283



More information about the R-help mailing list