When I was computing some joint probabilities, I found that R reported most of the results to to -Inf and thus didn't record the value. I guess it is b/c the joint log(probability) can be extremely small. Is there a way in R to keep the values even if they are small?
R can hold very small numbers. It is the round-off error during addition (and other basic operations) that causes the problem. For example:> x=1e-300 > x[1] 1e-300> (x+1)-1[1] 0 If you need a code that can be immune to round-off problems - you need to write it yourself (please correct me if I am wrong). At some point I needed 'sum' and 'cumsum' that would not have that problem and I end up writing my own versions of those functions. See examples of 'sum.exact' and 'cumsum.exact' in 'caTools' package. Jarek Tuszynski -----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] Sent: Thursday, September 22, 2005 12:53 PM To: r-help at stat.math.ethz.ch Subject: [R] how to keep very small or large number? When I was computing some joint probabilities, I found that R reported most of the results to to -Inf and thus didn't record the value. I guess it is b/c the joint log(probability) can be extremely small. Is there a way in R to keep the values even if they are small? ______________________________________________ R-help at 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
On 9/22/2005 12:52 PM, Cunningham Kerry wrote:> When I was computing some joint probabilities, I found > that R reported most of the results to to -Inf and > thus didn't record the value. I guess it is b/c the > joint log(probability) can be extremely small. Is > there a way in R to keep the values even if they are > small?Leave them in log form, take exponentials only when you need to report them. Duncan Murdoch
Your question is too vague for me. Can you please provide a very simple example in a few lines of code? For example, do you first compute probabilities and then take logarithms, or do you try to compute logarithms directly? Where exactly do you see the problem? (The posting guide www.R-project.org/posting-guide.html might help.) spencer graves Cunningham Kerry wrote:> When I was computing some joint probabilities, I found > that R reported most of the results to to -Inf and > thus didn't record the value. I guess it is b/c the > joint log(probability) can be extremely small. Is > there a way in R to keep the values even if they are > small? > > ______________________________________________ > R-help at 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-- Spencer Graves, PhD Senior Development Engineer PDF Solutions, Inc. 333 West San Carlos Street Suite 700 San Jose, CA 95110, USA spencer.graves at pdf.com www.pdf.com <http://www.pdf.com> Tel: 408-938-4420 Fax: 408-280-7915
Suppose I have n=1000 cases. For each case, the probability can go like 1e-10, then I have to multiply these probabilities together to get joint probability. I tried to do the following: p=1 x1=runif(n,0,1) x2=runif(n,0,1) y=ifelse(runif(m) < plogis(-6+6*x1+6*x2), 1, 0); pta0=-6 pta1=6 pta2=6 for(i in 1:n) { p <- p*exp((y[i]*log(plogis(pta0+pta1*x1[i]+pta2*x2[i]))+(1-y[i])*log(1-plogis(pta0+pta1*x1[i]+pta2*x2[i])))) } but the result is shown to be zero. --- Cunningham Kerry <kerryrekky at yahoo.com> wrote:> When I was computing some joint probabilities, I > found > that R reported most of the results to to -Inf and > thus didn't record the value. I guess it is b/c the > joint log(probability) can be extremely small. Is > there a way in R to keep the values even if they are > small? > > > > > __________________________________> http://mail.yahoo.com >