[R] puzzle with integrate over infinite range

Duncan Murdoch murdoch.duncan at gmail.com
Tue Sep 21 19:41:40 CEST 2010


  On 21/09/2010 1:29 PM, baptiste auguie wrote:
> I see, thank you.
>
> I'm still worried by the very dramatic error I obtained just from
> shifting so slightly the support of the integrand, it took me a while
> to figure what happened even with this basic example (I knew the
> integral couldn't be so small!).
>
> For a general integration in [0, infty), there must be a link between
> the number of quadrature points, the transformation applied to the
> integrand, and the region (position, width) where the measurable
> integrand needs to be in order to be sampled by the quadrature. I
> guess this kind of info lies deep inside the source code though.

You probably do have to look at the source code to find out the rule, 
but it is very easy to find out how it applies for any particular set of 
parameters:  Just have your objective function print or save all the 
points where it is asked to evaluate itself.  Plotting those will be 
very informative.

Duncan Murdoch

> Thanks,
>
> baptiste
>
>
>
> On 21 September 2010 19:00, Thomas Lumley<tlumley at u.washington.edu>  wrote:
> >  On Tue, 21 Sep 2010, baptiste Auguié wrote:
> >
> >>  Thanks, I'll do that too from now on.
> >>  It strikes me that in a case such as this one it may be safer to use a
> >>  truncated, finite interval around the region where the integrand is
> >>  non-zero, rather than following the advice of ?integrate to use Inf as
> >>  integration limit. At least one wouldn't risk to get an entirely wrong
> >>  result depending on a choice of rel.tol. Regarding this parameter, is there
> >>  a simple interpretation of how it affected the result in the context of my
> >>  example?
> >>
> >
> >  Not really.
> >
> >  If you know where the integrand is non-zero then you can shift it so that
> >  integrate() can handle it.  If you don't know then you can't get the
> >  truncated interval right.
> >
> >  The truncation approach works well for the Normal density because it it is
> >  non-negative, symmetric, and has nearly bounded support. The truncation
> >  error goes down extremely fast and if the mode of the density is in the
> >  center of the interval then all the mass can easily be found.   If you have
> >  a function with multiple modes and heavier tails it is harder to get an
> >  interval that is large enough to make the truncation error small, and still
> >  allows the integrate() function to find all the mass.
> >
> >      -thomas
> >
> >  Thomas Lumley
> >  Professor of Biostatistics
> >  University of Washington, Seattle
> >
>
>
>



More information about the R-help mailing list