I would define all the arguments that are used in this function. I mean:
my.theta1 <- 0.2
my.theta2 <- 2
f <- function(u, theta1, theta2)
{
dgamma(u, shape=1/theta1, scale=theta1) *
(dgamma(u, shape=1/theta1, scale=theta1, log=TRUE) -
dgamma(u, shape=1/theta2, scale=theta2, log=TRUE))
}
f <- Vectorize(f)
integrate(f, lower=0, upper=Inf, theta1 = my.theta1, theta2 = my.theta2)
Being more explicit, to prevent "accidents" because your function performs a search theta1, and theta2in the higher (global) media (which can become messy if you use this function deep within the program).
source
share