[R] How to set the floating point precision beyond e-22?

Duncan Murdoch murdoch at stats.uwo.ca
Fri Aug 5 12:45:38 CEST 2005


Roy Nitze wrote:
> We have a problem inverting a matrix which has the following eigenvalues:
>  
> 
>>eigen(tcross, only.values=TRUE)
> 
> $values
>  [1]  7.917775e+20  2.130980e+16  7.961620e+13  8.241041e+12  2.258325e+12
>  [6]  3.869428e+11  6.791041e+10  2.485352e+09  9.863098e+08  9.819373e+05
> [11]  3.263408e+05  2.929853e+05  2.920419e+05  2.714355e+05  8.733435e+04
> [16]  8.127136e+04  6.543883e+04  5.335074e+04  3.773311e+04  2.904373e+04
> [21]  2.418297e+04  1.387422e+04  8.925090e+03  5.538344e+03  4.831908e+03
> [26]  1.133571e+03  9.882477e+02  7.725812e+02  5.081682e+02  3.010545e+02
> [31]  1.801611e+02  1.319787e+02  1.050521e+02  7.096471e+01  5.576549e+01
> [36]  4.192645e+01  3.549810e+01  2.638731e+01  2.444429e+01  1.735139e+01
> [41]  1.058796e+01  7.425778e+00  7.209576e+00  4.689665e+00  3.181650e+00
> [46]  3.002956e+00  1.959247e+00  1.551665e+00  1.079589e+00  1.064981e+00
> [51]  5.409617e-01  4.076501e-01  2.010129e-01  1.302394e-01  4.029787e-02
> [56]  2.599448e-02  1.061294e-02  1.634286e-03  4.095303e-09  1.021885e-10
> [61]  2.124763e-11  6.906665e-12  2.850103e-12  9.440867e-13  6.269723e-13
> [66]  1.043794e-13 -1.300171e-13 -7.220665e-13 -4.166945e-12 -6.145350e-12
> [71] -2.776804e-11 -5.269669e-11 -7.154246e-10 -1.490515e-09 -1.294256e-08
> [76] -1.224821e-02 -3.278657e+00 -4.620100e+01 -9.781843e+02 -1.303929e+04
> [81] -5.545949e+04 -8.077540e+04 -8.577861e+04 -1.329961e+05 -1.450908e+05
> [86] -3.022353e+05 -4.015776e+05
> 
> As yout can see, the eigenvalues spread very much (between e+20 and e-13).
> We presume, that it has something to do with R's floating point precision,
> which I read is about 22-digits in mantissa as default.

Less than that.  It depends a bit on the platform and the exact 
calculation, but you can't count on more than 15-16 decimal digits 
precision.

> Can this precision
> be set to values above 22? 

No.  R generally uses the floating point hardware type "double 
precision", and it's a fixed size.

The problem occurs especially when trying to
> perform 2SLS with the 'systemfit' package. There appears always an error
> message like the following from the inverting routine:
>  
> solve(tcross)
> Error in solve.default(tcross) : Lapack routine dgesv: system is exactly
> singular

You will have to find a different solution to the problem.  To machine 
precision, that matrix looks singular.  This usually indicates that it's 
not the right matrix to try to invert.

Duncan Murdoch




More information about the R-help mailing list