# [R] Integral of PDF

Fri Dec 3 19:24:19 CET 2010

```Yes, Albyn.  I do not think that this is a dangerous behavior of the tool
(`integrate').  It is certainly a "dangerous use" of the tool.  One will be
hard-pressed to find a numerical algorithm/software that is fool-proof in
the sense that it always gives you either the correct results or warns you
that the results could be wrong for your problem.  We can always devise a
problem to defeat even the most robust algorithm.  So, I would argue that
the ultimate responsibility lies with the user, via careful thinking/prior
analysis/ and multiple types of checks, to ensure that the results are
reasonably accurate.

This, of course, does not mean that `integrate' gets away scot free.  I am
sure it could be improved, but I am also quite certain that there are better
quadrature algorithms.  So, one needs to choose appropriate algorithms to
suit their problem needs.  Perhaps, the simplest thing to do for `integrate'
might be to print a generic warning like:  "The error estimate is not always
reliable".  Of course, this does not help the user since they would not know
when it is NOT reliable. The next thing to try might be to examine how it
picks the initial interval [0, x], and see if this procedure can be
improved.

Best,
Ravi.

-------------------------------------------------------
Assistant Professor,
Division of Geriatric Medicine and Gerontology School of Medicine Johns
Hopkins University

Ph. (410) 502-2619
email: rvaradhan at jhmi.edu

-----Original Message-----
From: Albyn Jones [mailto:jones at reed.edu]
Sent: Thursday, December 02, 2010 6:41 PM
Cc: 'Hans W Borchers'; r-help at r-project.org
Subject: Re: [R] Integral of PDF

On Thu, Dec 02, 2010 at 06:23:45PM -0500, Ravi Varadhan wrote:

> A simple solution is to locate the mode of the integrand, which should be
> quite easy to do, and then do a coordinate shift to that point and then
> integrate the mean-shifted integrand using `integrate'.
>
> Ravi.

Translation:  think before you compute!

albyn

```