One-dimensional/Multi-dimensional numerical integration in R

谢益辉 2007-04-14

More than one members have asked such questions in COS, and they can be easily solved by the function integrate (pkg stats) and adapt (pkg adapt). For example:

> fnorm = function(x) {
    1/sqrt(2 * pi) * exp(-x^2/2)
}

> integrate(fnorm, -Inf, 0)
0.5 with absolute error < 4.7e-05
> pnorm(0)
[1] 0.5