[R] Surprising result from integrate
Thomas Lumley
tlumley at u.washington.edu
Fri Aug 23 20:08:46 CEST 2002
On Fri, 23 Aug 2002, Daniel Hoppe wrote:
> Hi all,
>
> sorry for this extensive question, but I think that I'm missing something
> fundamental.
>
> I stepped into a surprising result with the integrate function and I would
> be glad if someone could put some light onto this. I try to integrate over
> an s-shaped growth-function. The results from this calculation seem to be
> correct for small values of t. Just for fun I tried some large values and
> suddenly one part of the formula got close to zero (i2, it is not expected
> to do this). I tried different numbers and found that for t=upper=59954
> everything is fine and for t=upper=59955 integrate wouldn't return the
> correct result anymore (see below). I'm now wondering if I'm misinterpreting
> how integrate is supposed to be used. Details can be found below.
>
The problem is that f2 is nearly zero for most of its range, eg for
t=100, it is 6.4e-11. The integrate() function only evaluates the function
at finitely many places and at some point it gets zero at all these points
and doesn't notice the tiny region where f2 is non-zero.
If you really want to integrate out to infinity then say so:
> bergernasr.clv.continuous(Inf)
112.1139 with absolute error < 1.2e-12
150.2340 with absolute error < 0.0010
[1] 282.3478
and it will work.
You can see a simpler version of the same thing with dnorm:
> integrate(dnorm,0,2)
0.4772499 with absolute error < 5.3e-15
> integrate(dnorm,0,20)
0.5 with absolute error < 3.7e-05
> integrate(dnorm,0,200)
0.5 with absolute error < 1.6e-07
> integrate(dnorm,0,2000)
0.5 with absolute error < 4.4e-06
> integrate(dnorm,0,20000)
0 with absolute error < 0
-thomas
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list