Skip to content

errors in integrate function?

2 messages · Ole Christensen, Thomas Lumley

#
Dear Richard

I think the cause of your problem with integrate() can be seen from
plotting the function you want integrate :

gamma.by.normal <- function(y,x,shape,scale,stdev) {
   return(
dgamma(y,shape=shape,scale=scale)*dnorm(x=x-y,mean=0,sd=stdev) ) 
}

curve(gamma.by.normal(x,x=10,shape=1,scale=4,stdev=0.2),from=8, to=12)

shows that most of the probability mass is between 9.3 and 10.7. You are
integrating this function from zero to infinity by a procedure that
choses the discretisation points in an automatic way (which may not give
any points in [9.3;10.7] ).

In my experience, one should be suspicuous when using the integrate()
function. Always plot the function to see how it looks like.

You are probably aware that for integer values of the shape parameter,
you should not use numeric integration to calculate the integral. Closed
form expression exist. 

Cheers Ole

  
    
#
On Mon, 25 Feb 2002, Ole Christensen wrote:

            
Yes, but integrate() still seems to be unduly optimistic about its
accuracy -- eight orders of magnitude is a lot to be wrong by.


	-thomas

Thomas Lumley			Asst. Professor, Biostatistics
tlumley at u.washington.edu	University of Washington, Seattle


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._