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. Can this precision be set to values above 22? 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 Or is there another source of error? We would like to embed R-routines in a non-commercial web application for which we need to employ 'systemfit' together with individual, user-submitted data. So the problem needs a general solution and not a special one for this particular matrix. Thanks in advance Roy PS: The 'gmp' package is definitely not the solution. I already tried it. [[alternative HTML version deleted]]
-----Ursprüngliche Nachricht----- Von: Roy Nitze [mailto:rnitze@wiwi.uni-bielefeld.de] Gesendet: Freitag, 5. August 2005 10:38 An: 'r-help@stat.math.ethz.ch' Betreff: How to set the floating point precision beyond e-22? 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. Can this precision be set to values above 22? 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 Or is there another source of error? We would like to embed R-routines in a non-commercial web application for which we need to employ 'systemfit' together with individual, user-submitted data. So the problem needs a general solution and not a special one for this particular matrix. Thanks in advance Roy PS: The 'gmp' package is definitely not the solution. I already tried it. [[alternative HTML version deleted]]
Duncan Murdoch
2005-Aug-05 10:45 UTC
[R] How to set the floating point precision beyond e-22?
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 > singularYou 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
>> >> 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.> It might be a scaling issue though: If you're measuring age in days > and hormone concentrations in Molar, then you'll get that sort of > eigenvalue ratios in a fairly benign way.I'm quite aware of that problem, but we have to deal with certain economic variables which are usually given in a certain dimension. So it is difficult to force all values to a certain order. The other thing is, that i.e. EViews is able to perform 2SLS in the same regression setup. Don't they have to invert the same matrices? If so, how do they do it and how can we mimic their proceeding in R? Scaling and Rescaling? What about the interpretation of the coefficients computed on a scaled basis and given in the context of re-/unscaled data? I'm not quite clear about it. Thanks to all of you.
>> >> 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.> It might be a scaling issue though: If you're measuring age in days > and hormone concentrations in Molar, then you'll get that sort of > eigenvalue ratios in a fairly benign way.I'm quite aware of that problem, but we have to deal with certain economic variables which are usually given in a certain dimension. So it is difficult to force all values to a certain order. The other thing is, that i.e. EViews is able to perform 2SLS in the same regression setup. Don't they have to invert the same matrices? If so, how do they do it and how can we mimic their proceeding in R? Scaling and Rescaling? What about the interpretation of the coefficients computed on a scaled basis and given in the context of re-/unscaled data? I'm not quite clear about it. Thanks to all of you.
Douglas Bates
2005-Aug-05 13:23 UTC
[R] How to set the floating point precision beyond e-22?
On 8/5/05, Roy Nitze <rnitze at wiwi.uni-bielefeld.de> 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. Can this precision > be set to values above 22? 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 > > Or is there another source of error? We would like to embed R-routines in a > non-commercial web application for which we need to employ 'systemfit' > together with individual, user-submitted data. So the problem needs a > general solution and not a special one for this particular matrix.It appears that you are using the crossproduct but not taking advantage of the symmetry. The condition number of the crossproduct is the square of the condition number of the original matrix so you are making your conditioning problems much worse by taking the crossproduct. I suggest that you use a QR or SVD decomposition of the original model matrix instead. You will still end up with a very ill-conditioned problem but now quite as bad as the one you have now.