Re: [R] (arbitrary) precision
Gabor Grothendieck wrote: Michael Grottke Michael.Grottke at duke.edu writes: : I am currently using R for fitting a model to various data sets : (minimizing the negative log-likelihood) and calculating a number of : metrics based on the parameter estimates. Within these calculations, I : have steps of the form : : log(log(1+x)), : : where x can be very small (e.g., around 1e-16). Unfortunately, the : precision of doubles does not suffice for coping with the difference in : the orders of magnitude of 1 and x: 1+x is rounded to 1. : : One way for solving this problem seems to be to use an arbitrary : precision library implemented in C and call the respective routines for : calculating the logarithm(s) from within R. : : My questions are as follows: : 1. Is there any better/more direct way to solve the problem? : 2. Is there any arbitrary precision library you can suggest in particular? : The approximation log(1+x) = x would be accuate to several decimal places in your case so your expression would reduce to log(log(1+x)) = log(x). __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html see also ?log1p Kjetil -- Kjetil Halvorsen. Peace is the most effective weapon of mass construction. -- Mahdi Elmandjra -- No virus found in this outgoing message. Checked by AVG Anti-Virus. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] (arbitrary) precision
Michael Grottke Michael.Grottke at duke.edu writes: : I am currently using R for fitting a model to various data sets : (minimizing the negative log-likelihood) and calculating a number of : metrics based on the parameter estimates. Within these calculations, I : have steps of the form : : log(log(1+x)), : : where x can be very small (e.g., around 1e-16). Unfortunately, the : precision of doubles does not suffice for coping with the difference in : the orders of magnitude of 1 and x: 1+x is rounded to 1. : : One way for solving this problem seems to be to use an arbitrary : precision library implemented in C and call the respective routines for : calculating the logarithm(s) from within R. : : My questions are as follows: : 1. Is there any better/more direct way to solve the problem? : 2. Is there any arbitrary precision library you can suggest in particular? : The approximation log(1+x) = x would be accuate to several decimal places in your case so your expression would reduce to log(log(1+x)) = log(x). __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] (arbitrary) precision
Gabor Grothendieck wrote: Michael Grottke Michael.Grottke at duke.edu writes: : I am currently using R for fitting a model to various data sets : (minimizing the negative log-likelihood) and calculating a number of : metrics based on the parameter estimates. Within these calculations, I : have steps of the form : : log(log(1+x)), : : where x can be very small (e.g., around 1e-16). Unfortunately, the : precision of doubles does not suffice for coping with the difference in : the orders of magnitude of 1 and x: 1+x is rounded to 1. : : One way for solving this problem seems to be to use an arbitrary : precision library implemented in C and call the respective routines for : calculating the logarithm(s) from within R. : : My questions are as follows: : 1. Is there any better/more direct way to solve the problem? : 2. Is there any arbitrary precision library you can suggest in particular? : The approximation log(1+x) = x would be accuate to several decimal places in your case so your expression would reduce to log(log(1+x)) = log(x). Another possibility is to use the log1p function to evaluate log1p(x) = log(1+x). The two expressions give similar answers in this case options(digits=12) log(log1p(1e-16)) [1] -36.8413614879 log(1e-16) [1] -36.8413614879 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html