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
______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.