Skip to content

adaptIntegrate - how to pass additional parameters to the integrand

5 messages · HC, Uwe Ligges, Ravi Varadhan +1 more

HC
#
Hello,

I am trying to use adaptIntegrate function but I need to pass on a few
additional parameters to the integrand. However, this function seems not to
have the flexibility of passing on such additional parameters.

Am I missing something or this is a known limitation. Is there a good
alternative to such restrictions, if there at all are?

Many thanks for your time.
HC


--
View this message in context: http://r.789695.n4.nabble.com/adaptIntegrate-how-to-pass-additional-parameters-to-the-integrand-tp3491701p3491701.html
Sent from the R help mailing list archive at Nabble.com.
#
On 03.05.2011 06:43, HC wrote:
Looks like you are talking about the cubature package rather than about 
base R. Frr the latter question: Please ask the package maintainer 
rather than the list. Ideally send him code to implement the requested 
feature and the maintainer will probably add your code. Not all package 
maintainers read R-help.

For an ad hoc solution:

Just use

adaptIntegrate(function(x, argA=a, argB=b) f(x, argA=argA, argB=argB), 
......)

in order to set additional arguments for the function call.

Uwe Ligges
#
Ok, I get it.

require(cubature)

f <- function(x, a) cos(2*pi*x*a)  # a simple test function

# this works
a <- 0.2
adaptIntegrate(function(x, argA=a) f(x, a=argA), lower=0, upper=2)

# but this doesn't work
rm(a)
adaptIntegrate(function(x, argA=a) f(x, a=argA), lower=0, upper=2, a=0.2)

Ravi.
#
Hi,

The package maintainer is aware of this feature request. In the
meantime, I've used Currying,


require(cubature)

f <- function(x, a) cos(2*pi*x*a)  # a simple test function

adaptIntegrate(roxygen::Curry(f, a=0.2), lower=0, upper=2)

HTH,

baptiste
On 4 May 2011 05:57, Ravi Varadhan <rvaradhan at jhmi.edu> wrote: