I need to perform some calculations with some extremely small numbers (i.e. likelihood values on the order of 1.0E-16,000). Even when using the double() function, R is rounding these values to zero. Is there any way to get R to deal with such small numbers? For example, I would like to be able to calculate e^-10000 (i.e. exp(-10000)) without the result being rounded to zero. I know I can do it in Mathematica, but I would prefer to use R if I can. Any help would be appreciated! Many Thanks in Advance! -- View this message in context: http://www.nabble.com/Beyond-double-precision--tp23452471p23452471.html Sent from the R help mailing list archive at Nabble.com.
Are all your numbers positive? If yes, have you considered using logarithms? I would guess it is quite rare for people to compute likelihoods. Instead I think most people use log(likelihoods). Most of the probability functions in R have an option of returning the logarithms. Hope this helps. Spencer joaks1 wrote:> I need to perform some calculations with some extremely small numbers (i.e. > likelihood values on the order of 1.0E-16,000). Even when using the > double() function, R is rounding these values to zero. Is there any way to > get R to deal with such small numbers? > > For example, I would like to be able to calculate e^-10000 (i.e. > exp(-10000)) without the result being rounded to zero. > > I know I can do it in Mathematica, but I would prefer to use R if I can. > Any help would be appreciated! > > Many Thanks in Advance! >
The following packages support high precision precision arithmetic (and the last two also support exact arithmetic): bc - interface to bc calculator http://r-bc.googlecode.com gmp - interface to gmp (gnu multiple precision) http://cran.r-project.org/web/packages/gmp rSymPy - interface to sympy computer algebra system http://rsympy.googlecode.com Ryacas - interface to yacas computer algebra system http://ryacas.googlecode.com On Fri, May 8, 2009 at 4:54 PM, joaks1 <joaks1 at gmail.com> wrote:> > I need to perform some calculations with some extremely small numbers (i.e. > likelihood values on the order of 1.0E-16,000). ?Even when using the > double() function, R is rounding these values to zero. ?Is there any way to > get R to deal with such small numbers? > > For example, I would like to be able to calculate e^-10000 (i.e. > exp(-10000)) without the result being rounded to zero. > > I know I can do it in Mathematica, but I would prefer to use R if I can. > Any help would be appreciated! > > Many Thanks in Advance! > -- > View this message in context: http://www.nabble.com/Beyond-double-precision--tp23452471p23452471.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org 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. >
joaks1 wrote:> I need to perform some calculations with some extremely small numbersThe R package Brobdingnag does this. It uses logarithmic representation, as recommended by others in this thread, but wraps it all up for you in a custom numeric class so you can use them as any other numeric type. http://cran.r-project.org/web/packages/Brobdingnag/vignettes/brobpaper.pdf