Re: [R] adaptIntegrate - how to pass additional parameters to the integrand

From: Ravi Varadhan <rvaradhan_at_jhmi.edu>
Date: Tue, 03 May 2011 13:57:39 -0400

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.



From: r-help-bounces_at_r-project.org [r-help-bounces_at_r-project.org] On Behalf Of Uwe Ligges [ligges_at_statistik.tu-dortmund.de] Sent: Tuesday, May 03, 2011 7:17 AM
To: HC
Cc: r-help_at_r-project.org
Subject: Re: [R] adaptIntegrate - how to pass additional parameters to the integrand

On 03.05.2011 06:43, HC wrote:
> 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?

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

> 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.
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.

R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Thu 05 May 2011 - 06:25:04 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 05 May 2011 - 07:00:05 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive