I find the one-dimensional "integrate" very helpful, but often enough I stumble into problems that require two (or more)-dimensional integrals. I suppose there are no R functions that can do this for me, "directly"? The ideal thing would be to be able to define say f <- function(x) { x1 <- x[1] x2 <- x[2] sin(x1*x2)*exp(x1-x2) } and then write say integrate(f, xlim=c(0,1), ylim=c(0,1)) . (a) No such thing exists, as of today, right? (b) There *are* general numerical routines "out there" for doing such things, right? (Importance sampling or adaptive important sampling would often do the job, but it would be difficult to find something that "always" works -- at least in higher dimension? Also, iterated one-dimensional integrations could be attempted, but I find that messy, also because things lose the g(many) = many(g) property, and then R refuses to integrate g.) (c) Will a thing like the above exist in R before the Tromsoe Olympics in 2014? For which dimensions? Nils Lid Hjort [Professor of statistics at Oslo, but currently at Duke]
Nils, For 2D, see package 'adapt' on CRAN. e.g. adapt(2, c(0,0), c(1,1), functn=function(x) sin(prod(x))*exp(x[1]-x[2])) Package `adapt' will do larger numbers of dimensions, but numerical quadrature is often no more effective than Monte-Carlo methods in more than a few dimensions. For very smooth functions, quasi-random numbers can help. A good reference aimed at statisticians is @Book{Evans.Swartz.00, author = {Michael Evans and Tim Swartz}, title = {Approximating Integrals via Monte Carlo and Deterministic Methods}, publisher = {Oxford University Press}, year = 2000, address = {Oxford}, ISBN = "0-19-850278-8", } BTW, we are not good are predicting to 2014, but fairly good at the present. In this case I could not guess a good search term on http://search.r-project.org, but it often gets you there. It has a `complete' list of packages, as does CRAN, and searching those pages for `integrate' works. Brian On Thu, 10 Mar 2005, Nils-at-Duke Lid Hjort wrote:> I find the one-dimensional "integrate" very helpful, > but often enough I stumble into problems that require > two (or more)-dimensional integrals. I suppose there > are no R functions that can do this for me, "directly"? > > The ideal thing would be to be able to define say > f <- function(x) > { > x1 <- x[1] > x2 <- x[2] > sin(x1*x2)*exp(x1-x2) > } > and then write say > integrate(f, xlim=c(0,1), ylim=c(0,1)) . > > (a) No such thing exists, as of today, right? > (b) There *are* general numerical routines "out there" > for doing such things, right? (Importance sampling > or adaptive important sampling would often do the > job, but it would be difficult to find something that > "always" works -- at least in higher dimension? > Also, iterated one-dimensional integrations could > be attempted, but I find that messy, also because > things lose the g(many) = many(g) property, and > then R refuses to integrate g.) > (c) Will a thing like the above exist in R before > the Tromsoe Olympics in 2014? For which dimensions? > Nils Lid Hjort > [Professor of statistics at Oslo, but currently at Duke]-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
This existed even before the Athens Olympics 2004 :) look at package "adapt" which integrates a function from 2 to 20 dimensions, e.g., library(adapt) f <- function(x){ x1 <- x[1] x2 <- x[2] sin(x1*x2)*exp(x1-x2) } adapt(2, c(0,0), c(1,1), functn=f) I hope it helps. Best, Dimitris ---- Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/16/336899 Fax: +32/16/337015 Web: http://www.med.kuleuven.ac.be/biostat/ http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm ----- Original Message ----- From: "Nils-at-Duke Lid Hjort" <hjort at isds.duke.edu> To: <R-help at stat.math.ethz.ch>; <nils at math.uio.no> Sent: Thursday, March 10, 2005 6:22 AM Subject: [R] two-dimensional integration?>I find the one-dimensional "integrate" very helpful, > but often enough I stumble into problems that require > two (or more)-dimensional integrals. I suppose there > are no R functions that can do this for me, "directly"? > > The ideal thing would be to be able to define say > f <- function(x) > { > x1 <- x[1] > x2 <- x[2] > sin(x1*x2)*exp(x1-x2) > } > and then write say > integrate(f, xlim=c(0,1), ylim=c(0,1)) . > > (a) No such thing exists, as of today, right? > (b) There *are* general numerical routines "out there" > for doing such things, right? (Importance sampling > or adaptive important sampling would often do the > job, but it would be difficult to find something that > "always" works -- at least in higher dimension? > Also, iterated one-dimensional integrations could > be attempted, but I find that messy, also because > things lose the g(many) = many(g) property, and > then R refuses to integrate g.) > (c) Will a thing like the above exist in R before > the Tromsoe Olympics in 2014? For which dimensions? > Nils Lid Hjort > [Professor of statistics at Oslo, but currently at Duke] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html >
Nils-at-Duke Lid Hjort <hjort at isds.duke.edu> writes:> I find the one-dimensional "integrate" very helpful, > but often enough I stumble into problems that require > two (or more)-dimensional integrals. I suppose there...> (c) Will a thing like the above exist in R before > the Tromsoe Olympics in 2014? For which dimensions? Nils Lid Hjort > [Professor of statistics at Oslo, but currently at Duke]Did you check the CRAN package "adapt"? It's been around at least since Nagano 1998, I believe. -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
Reasonably Related Threads
- functions for high dimensional integral
- multivariate integral with ADAPT when the parameter is close to boundary
- Nested instruction patterns rejected by GlobalISel when having registers in Defs
- Olympics: 200m Men Final
- Nested instruction patterns rejected by GlobalISel when having registers in Defs