From Peter.Ruckdeschel at uni-bayreuth.de  Tue Jul  3 17:26:43 2007
From: Peter.Ruckdeschel at uni-bayreuth.de (Peter Ruckdeschel)
Date: Tue, 03 Jul 2007 17:26:43 +0200
Subject: [Rd] minor flaw in integrate()
In-Reply-To: <18058.3245.990602.638911@stat.math.ethz.ch>
References: <46842286.8080402@uni-bayreuth.de>	<4689ACC7.6010005@stats.uwo.ca>
	<18058.3245.990602.638911@stat.math.ethz.ch>
Message-ID: <468A6AB3.60509@uni-bayreuth.de>

Thanks Martin and Duncan for your
comments,

Martin Maechler wrote:
>>>>>> "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.

not quite convinced --- or more precisely:

[ Let's assume lower = upper = Inf here,
  case lower = upper = -Inf is analogue ]

I'd say it depends on whether the (Lebesgue-) integral

   integral(f, lower = <some finite value>, upper = Inf)

is well defined. Then, by dominated convergence, the integral should
default to 0.

But I admit that then a test

     is.finite(integrate(f, lower = <some finite value>, upper = Inf)$value)

would be adequate, too, which makes evaluation a little more expensive :-(

If, otoh

   integrate(f, lower = <some finite value>, upper = Inf)

throws an error, I agree, there should be a NaN ...
Best, Peter



[Rd] minor flaw in integrate()
Peter Ruckdeschel