On 11-Apr-07 15:59:09, Jeann S wrote: > Dear all, > > Sorry for bringing up an old issue: > > >pexp(50, 0.5) > [1] 1 > > In some cases, pexp() gives CDF=1. I read some discussion > in 2002 saying it has been patched. However it's not working > in "R2.4.1Patched". Could anyone help me out? > > Thanks a lot, > > Jeann
Since pexp(x,a) = 1 - exp(-a*x), you can use this expression instead of pexp(), or exp(-a*x) instead of 1 - pexp(a*x). Comparison of the two forms (on an older version of R but presumably the results are the same as you are referring to): x <- 5*(1:12); y <- pexp(x,1); z <- 1 - exp(-1*x) -log(1-y) [1] 5.00000 10.00000 15.00000 20.00000 25.00000 29.99983 34.94504 [8] Inf Inf Inf Inf Inf -log(1-z) [1] 5.00000 10.00000 15.00000 20.00000 25.00000 29.99983 34.94504 [8] Inf Inf Inf Inf Inf so, looked at in this way, there is no difference. However: x <- 5*(1:12); y <- pexp(x,1,lower.tail=FALSE); z <- 1 - exp(-1*x) -log(y) [1] 5 10 15 20 25 30 35 40 45 50 55 60 -log(1-z) [1] 5.00000 10.00000 15.00000 20.00000 25.00000 29.99983 34.94504 [8] Inf Inf Inf Inf Inf And: x <- 5*(1:12); y <- pexp(x,1,lower.tail=FALSE); z <- exp(-1*x) -log(y) [1] 5 10 15 20 25 30 35 40 45 50 55 60 -log(z) [1] 5 10 15 20 25 30 35 40 45 50 55 60 so clearly exactly the same problem arises with -log(1 - exp(-x)) when x is large, as arises with pexp(x) when x is large, and I would put it down to the fact that 1 - exp(-x) is not very precise (in "significant figure" terms). Another way of looking at it: pexp(x,lower.tail=FALSE) [1] 6.737947e-03 4.539993e-05 3.059023e-07 2.061154e-09 [5] 1.388794e-11 9.357623e-14 6.305117e-16 4.248354e-18 [9] 2.862519e-20 1.928750e-22 1.299581e-24 8.756511e-27 1-(1-pexp(x,lower.tail=FALSE)) [1] 6.737947e-03 4.539993e-05 3.059023e-07 2.061154e-09 [5] 1.388789e-11 9.359180e-14 6.661338e-16 0.000000e+00 [9] 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 However, the quesiton arises: Why do you need the precision (about exp(-37) = 1e-16) in pexp(x) for large x? If you're interested in the difference from 1, then use "lower.tail=FALSE" in the first place, I would have thought? Best wishes, Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <[EMAIL PROTECTED]> Fax-to-email: +44 (0)870 094 0861 Date: 11-Apr-07 Time: 20:36:45 ------------------------------ XFMail ------------------------------ ______________________________________________ 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 and provide commented, minimal, self-contained, reproducible code.