Development

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • How to set the floating point precision beyond e-22?

    5 answers - 2574 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    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
    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]]
    R-help (AT) stat (DOT) math.ethz.ch mailing list
    PLEASE do read the posting guide!
  • No.1 | | 2692 bytes | |

    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

    R-help (AT) stat (DOT) math.ethz.ch mailing list

    PLEASE do read the posting guide!
  • No.2 | | 455 bytes | |

    Duncan Murdoch <murdoch (AT) stats (DOT) uwo.cawrites:

    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.
  • No.3 | | 827 bytes | |

    Peter Dalgaard wrote:
    Duncan Murdoch <murdoch (AT) stats (DOT) uwo.cawrites:


    >>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.

    Remember the old joke.

    The patient to his doctor: "It hurts when I do this."

    The doctor: "So don't do that."

    Duncan Murdoch

    R-help (AT) stat (DOT) math.ethz.ch mailing list

    PLEASE do read the posting guide!
  • No.4 | | 2974 bytes | |

    8/5/05, Roy Nitze <rnitze (AT) wiwi (DOT) uni-bielefeld.dewrote:
    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

    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.

    R-help (AT) stat (DOT) math.ethz.ch mailing list

    PLEASE do read the posting guide!
  • No.5 | | 3969 bytes | |

    And don't forget to rescale first, as Peter Dalgaard suggested.

    I've been giving this lecture for over 20 years, and I got caught by
    it myself a few years ago. I computed the crossproduct matrix, as Doug
    said, and had no end of trouble because it was numerically singular. I
    rescaled each column by subtracting some number roughly close to the
    mean or median and dividing by something close to the standard
    deviation, and the problem went away.

    spencer graves

    Douglas Bates wrote:

    8/5/05, Roy Nitze <rnitze (AT) wiwi (DOT) uni-bielefeld.dewrote:

    >>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
    >>

    >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.

    R-help (AT) stat (DOT) math.ethz.ch mailing list

    PLEASE do read the posting guide!

Re: How to set the floating point precision beyond e-22?


max 4000 letters.
Your nickname that display:
In order to stop the spam: 2 + 1 =
QUESTION ON "Development"

EMSDN.COM