link to CRAN: https://cran.r-project.org/web/packages/mvQuad/
This package provides a collection of methods for (potentially)
multivariate quadrature in R. It’s especially designed for use in
statistical problems, characterized by integrals of the form
In general quadrature (also named: numerical integration, numerical quadrature) work this way: The integral of interests is approximated by a weighted sum of function values.
The so called nodes (
This principle can be transferred directly to the multivariate case.
The methods provided in this package cover the following tasks:
This section shows a typical workflow for quadrature with the
mvQuad
-package. More details and additional features of
this package are provided in the subsequent sections. In this
illustration the following two-dimensional integral will be
approximated:
```{r } library(mvQuad)
# create grid nw <- createNIGrid(dim=2, type=“GLe”, level=6)
# rescale grid for desired domain rescale(nw, domain = matrix(c(1, 1, 2, 2), ncol=2))
# define the integrand myFun2d <- function(x){ x[,1]*exp(x[,2]) }
# compute the approximated value of the integral A <- quadrature(myFun2d, grid = nw) ```
Explanation Step-by-Step
mvQuad
-package is loadedcreateNIGrid
-command a two-dimensional
(dim=2
) grid, based on Gauss-Legendre quadrature rule
(type="GLe"
) with a given accuracy level
(level=6
) is created and stored in the variable
nw
The grid created above is designed for the domain
the command rescale
changes the domain-feature of
the grid; the new domain is passed in a matrix
(domain=...
)
the integrand is defined
the quadrature
-command computes the weighted sum of
function values as mentioned in the introduction
The choice of quadrature rule is heavily related to the integration
problem. Especially the domain/support (
The mvQuad
-packages provides the following quadrature
rules.
cNC1, cNC2, ..., cNC6
: closed
Newton-Cotes Formulas of degree 1-6 (1=trapezoidal-rule;
2=Simpson’s-rule; …), finite domain
oNC0, oNC1, ..., oNC3
: open
Newton-Cote Formula of degree 0-3 (0=midpoint-rule; …), finite
domain
GLe, GKr
: Gauss-Legendre and
Gauss-Kronrod rule, finite domain
nLe
: nested Gauss-Legendre rule
(finite domain) [@Petras2003]
Leja
: Leja-Points (finite
domain)
GLa
: Gauss-Laguerre rule
(semi-finite domain)
GHe
: Gauss-Hermite rule (infinite
domain)
nHe
: nested Gauss-Hermite rule
(infinite domain) [@GenzKeister1996]
GHN
, nHN
: (nested)
Gauss-Hermite rule as before but weights are pre-multiplied by the
standard normal density (
For each rule grids can be created of different accuracy. The
adjusting screw in the createNIGrid
is the
level
-option. In general, the higher level
the
more precise the approximation. For the Newton-Cotes rules an arbitrary
level can be chosen. The other rules uses lookup-tables for the nodes
and weights and are therefore restricted to a maximum level (see
help(QuadRules)
)