[Rd] Integration with exchanged and infinite limits

Ralf Stubner r@||@@tubner @end|ng |rom gm@||@com
Thu Jul 11 10:26:51 CEST 2019


Dear List,

while working on an update to my post on integrating over an infinite
range using RcppNumerical [1] I have encountered erroneous behavior
from integrate() when (at least) one of the limits is infinite and
upper and lower limit are exchanged, i.e. upper < lower. For example,
integrating dnorm with upper > lower works without problems:

integrate(dnorm, 0.1, 1)
#> 0.3015169 with absolute error < 3.3e-15
integrate(dnorm, 0.1, 10)
#> 0.4601722 with absolute error < 6.2e-06
integrate(dnorm, 0.1, Inf)
#> 0.4601722 with absolute error < 2.7e-05

If we interchange the limits, we get the expected negative value of
the previous integrals as long as the limits are finite:

integrate(dnorm, 1, 0.1)
#> -0.3015169 with absolute error < 3.3e-15
integrate(dnorm, 10, 0.1)
#> -0.4601722 with absolute error < 6.2e-06

But when the lower limit is Inf, the returned value is incorrect:

integrate(dnorm, Inf, 0.1)
#> 0.5398278 with absolute error < 7.5e-05

Instead of the expected -0.4601722, it is the value one would get when
the lower limit were -Inf:

integrate(dnorm, -Inf, 0.1)
#> 0.5398278 with absolute error < 7.5e-05

Similar problems occur if the upper limit is -Inf. The reason seems to
be that integrate() assumes that if is.finite() is false for lower
then lower == -Inf (similarly for upper).

Should this be fixed?

Greetings
Ralf

[1] https://stubner.me/2019/07/numerical-integration-in-rcpp/



More information about the R-devel mailing list