[R] [FORGED] Multiple Integrals
Rolf Turner
r.turner at auckland.ac.nz
Thu Jan 7 05:37:37 CET 2016
On 07/01/16 13:03, Luísa Freitas wrote:
> Dear R-helpers,
>
> I'm looking for a quick way to calculate triple integrals.
>
> I have tried something like this example:
>
> f <- function(x,y,z) dnorm(x)*dnorm(y)*dnorm(z)
> llim <- -Inf
> ulim <- Inf
> integrate(function(z)
> {
> sapply(z,function(z)
> {
> integrate(function(y)
> {
> sapply(y, function(y)
> {
> integrate(function(x) f(x,y,z), llim, ulim)$value
> })
> }, llim, ulim)$value
> })
> },llim,ulim)
>
> I'm not sure if there are other ways faster than this one.
> Any help will be appreciated.
GIYF. Searching on "multiple integration r" led me very quickly to the
R2Cuba package for multidimensional numerical integration, which will
presumably do what you want. (I have not tried it out; that's your job.)
cheers,
Rolf Turner
--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276
More information about the R-help
mailing list