[R] Looking for greater floating-point precision
Martin Maechler
maechler at stat.math.ethz.ch
Fri Nov 17 14:36:34 CET 2006
>>>>> "Paul" == Paul Smith <phhs80 at gmail.com>
>>>>> on Fri, 17 Nov 2006 12:12:52 +0000 writes:
Paul> On 11/16/06, Prof Brian Ripley <ripley at stats.ox.ac.uk>
Paul> wrote:
>> > For my calculations, I am needing to use more
>> floating-point precision > than the default one of R. Is
>> that possible? And, if yes, how?
>>
>> See package gmp (but that will be slow and cumbersome for
>> all but simple calculations).
>>
>> The real issue is that R already uses the maximum
>> precision of the FPU for many common FPUs (but not all).
>> Since you have forgotten to tell us anything about your
>> environment we don't know if that applies: there may be
>> compiler options you can use to raise the precision.
>>
>> Please do study the posting guide: we are surprisingly
>> good at mind-reading, but prefer to be told exactly what
>> you want to do with R in what environment and why you are
>> 'needing' something.
Paul> Thanks, Gabor and Prof. Ripley. After some research, I
Paul> conclude that the problem occurring to me cannot be
Paul> removed for any finite floating-point precision. (I do
Paul> need infinite floating-point precision.) The
Paul> problematic operation is the successive multiplication
Paul> of reals between 0 and 1; after a certain number of
Paul> multiplications, significant rounding errors occur.
of course. But that's a very well known and common problem in
several areas of applied probability and statistics.
AFAIK, in most cases the "obvious" remedy is the following:
Instead of multiplying probabilities,
you add log-probabilities and only exp()onentiate at the end {if
needed at all}. This also applies if your numbers in [0,1] are
not probabilities per se.
Note that R makes it particularly efficient to work with
log-probabilities, because all d<foo>() and p<foo> functions
have a 'log' or 'log.p' argument which return log-values
already, often with much more precision and efficiency than if
you'd take the log of the probabilities yourself.
Regards,
Martin Maechler, ETH Zurich
Paul> I did read the posting guide, but I could not
Paul> anticipate the relevance of indicating the environment
Paul> that I am using: Fedora Core 6 (Linux) running on a
Paul> Pentium Dual Core and R 2.4.0.
Paul> Paul
Paul> ______________________________________________
Paul> R-help at stat.math.ethz.ch mailing list
Paul> https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do
Paul> read the posting guide
Paul> http://www.R-project.org/posting-guide.html and
Paul> provide commented, minimal, self-contained,
Paul> reproducible code.
More information about the R-help
mailing list