Re: [R] Integral of PDF

2010-12-03 Thread Ravi Varadhan
rvarad...@jhmi.edu -Original Message- From: Albyn Jones [mailto:jo...@reed.edu] Sent: Thursday, December 02, 2010 6:41 PM To: Ravi Varadhan Cc: 'Hans W Borchers'; r-help@r-project.org Subject: Re: [R] Integral of PDF On Thu, Dec 02, 2010 at 06:23:45PM -0500, Ravi Varadhan wrote:

Re: [R] Integral of PDF

2010-12-03 Thread Ravi Varadhan
-project.org] On Behalf Of Hans W Borchers Sent: Friday, December 03, 2010 3:30 AM To: r-help@r-project.org Subject: Re: [R] Integral of PDF That does not remedy the situation in any case, take the following function fun <- function(x) dnorm(x, -500, 50) + dnorm(x, 500, 50) that has a 'mo

Re: [R] Integral of PDF

2010-12-03 Thread Samuel Le
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Doran, Harold Sent: 02 December 2010 21:22 To: r-help@r-project.org Subject: [R] Integral of PDF The integral of any probability density from -Inf to Inf should equal 1, correct? I don't understand last result below

Re: [R] Integral of PDF

2010-12-03 Thread Hans W Borchers
That does not remedy the situation in any case, take the following function fun <- function(x) dnorm(x, -500, 50) + dnorm(x, 500, 50) that has a 'mode' of 0 again. Interestingly, if I transform it by 1/x, to integrate I again have to reduce the error tolerance to at least 1e-10:

Re: [R] Integral of PDF

2010-12-02 Thread Albyn Jones
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: t

Re: [R] Integral of PDF

2010-12-02 Thread Ted Harding
Albyn's reply is in line with an hypothesis I was beginning to formulate (without looking at the underlying FoRTRAN code), prompted by the hint in '?integrate': Details: If one or both limits are infinite, the infinite range is mapped onto a finite interval. For a finite interval,

Re: [R] Integral of PDF

2010-12-02 Thread Ravi Varadhan
lto:r-help-boun...@r-project.org] On Behalf Of Hans W Borchers Sent: Thursday, December 02, 2010 5:16 PM To: r-help@r-project.org Subject: Re: [R] Integral of PDF You can dive into the thread "puzzle with integrate over infinite range" from September this year. The short answer app

Re: [R] Integral of PDF

2010-12-02 Thread William Dunlap
gt; From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of Doran, Harold > Sent: Thursday, December 02, 2010 1:22 PM > To: r-help@r-project.org > Subject: [R] Integral of PDF > > The integral of any probability density from -Inf to Inf > should e

Re: [R] Integral of PDF

2010-12-02 Thread Albyn Jones
To really understaand it you will have to look at the fortran code underlying integrate. I tracked it back through a couple of layers (dqagi, dqagie, ... just use google, these are old netlib subroutines) then decided I ought to get back to grading papers :-) It looks like the integral is split

Re: [R] Integral of PDF

2010-12-02 Thread Hans W Borchers
You can dive into the thread "puzzle with integrate over infinite range" from September this year. The short answer appears to be: Increase the error tolerance. integrate(function(x) dnorm(x, 500,50), -Inf, Inf, subdivisions=500, rel.tol=1e-11) # 1 with absolute error < 1.1e

[R] Integral of PDF

2010-12-02 Thread Doran, Harold
The integral of any probability density from -Inf to Inf should equal 1, correct? I don't understand last result below. > integrate(function(x) dnorm(x, 0,1), -Inf, Inf) 1 with absolute error < 9.4e-05 > integrate(function(x) dnorm(x, 100,10), -Inf, Inf) 1 with absolute error < 0.00012 > integr