Re: [Rd] minor flaw in integrate()

From: Martin Maechler <maechler_at_stat.math.ethz.ch>
Date: Tue, 03 Jul 2007 10:45:33 +0200

>>>>> "DM" == Duncan Murdoch <murdoch_at_stats.uwo.ca> >>>>> on Mon, 02 Jul 2007 21:56:23 -0400 writes:

    DM> On 28/06/2007 5:05 PM, Peter Ruckdeschel wrote:
>> Hi,
>>
>> I noticed a minor flaw in integrate() from package stats:
>>
>> Taking up arguments lower and upper from integrate(),
>>
>> if (lower == Inf) && (upper == Inf)
>>
>> or
>>
>> if (lower == -Inf) && (upper == -Inf)
>>
>> integrate() calculates the value for (lower==-Inf) && (upper==Inf).
>>
>> Rather, it should return 0.

    DM> Wouldn't it be better to return NA or NaN, for the same reason Inf/Inf     DM> doesn't return 1?

    DM> Duncan Murdoch

Yes indeed, I think it should return NaN. Martin

>>
>> Quick fix:
>>
>> ### old code ###
>> ### [snip]
>> else {
>> if (is.na(lower) || is.na(upper))
>> stop("a limit is missing")
>> if (is.finite(lower)) {
>> inf <- 1
>> bound <- lower
>> }
>> else if (is.finite(upper)) {
>> inf <- -1
>> bound <- upper
>> }
>> else {
>> inf <- 2
>> bound <- 0
>> }
>> wk <- .External("call_dqagi", ff, rho = environment(),
>> as.double(bound), as.integer(inf), as.double(abs.tol),
>> as.double(rel.tol), limit = limit, PACKAGE = "base")
>> }
>> ### [snip]
>>
>> ### new code to replace the old one ###
>>
>> ### [snip]
>> else {
>> if (is.na(lower) || is.na(upper))
>> stop("a limit is missing")
>>
>> if (lower == upper){
>>
>> wk <- list("value" = 0, "abs.error" = 0,
>> "subdivisions" = subdivisions,
>> "ierr" = 0 )
>>
>> } else {
>> if (is.finite(lower)) {
>> inf <- 1
>> bound <- lower
>> }
>> else if (is.finite(upper)) {
>> inf <- -1
>> bound <- upper
>> }
>> else {
>> inf <- 2
>> bound <- 0
>> }
>> wk <- .External("call_dqagi", ff, rho = environment(),
>> as.double(bound), as.integer(inf),
>> as.double(abs.tol), as.double(rel.tol),
>> limit = limit, PACKAGE = "base")
>>
>> }
>> }
>> ### [snip]
>>
>> Best, Peter
>>
>> ______________________________________________
>> R-devel_at_r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel

    DM> ______________________________________________
    DM> R-devel_at_r-project.org mailing list     DM> https://stat.ethz.ch/mailman/listinfo/r-devel

R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Tue 03 Jul 2007 - 08:49:12 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 03 Jul 2007 - 16:35:58 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.