Skip to content
Prev 17405 / 398513 Next

errors in integrate function?

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