Learn R Programming

EstimationTools (version 4.0.0)

gauss_quad: Numerical integration through Gaussian Quadrature

Description

[Experimental]

This family of functions use quadratures for solving integrals. The user can create a custom integration routine, see details for further information.

Usage

gauss_quad(
  fun,
  lower,
  upper,
  kind = "legendre",
  n = 10,
  normalized = FALSE,
  ...
)

Value

The value of the integral of the function specified in fun

argument.

Arguments

fun

an R function which should take a numeric argument x and possibly some parameters. The function returns a numerical vector value for the given argument x.

lower

a numeric value for the lower limit of the integral.

upper

a numeric value for the upper limit of the integral.

kind

character specifying the weight (polynomial) function for the quadrature.

n

integer with the highest order of the polynomial of the selected rule.

normalized

logical. If TRUE, rules are for orthonormal polynomials, otherwise they are for orthogonal polynomials.

...

additional arguments to be passed to fun and to the quadrature routine specified in argument kind.

Author

Jaime Mosquera Gutiérrez, jmosquerag@unal.edu.co

Details

gauss_quad uses the implementation of Gaussian quadratures from gaussquad package.This is a wrapper that implements rules and integration routine in the same place.

See Also

laguerre.quadrature, legendre.quadrature, chebyshev.c.quadrature, gegenbauer.quadrature, hermite.h.quadrature, etc.

Examples

Run this code
library(EstimationTools)

#----------------------------------------------------------------------------
# Example 1: Mean of X ~ N(2,1) (Gauss-Hermitie quadrature).
g <- function(x, mu, sigma) sqrt(2)*sigma*x + mu
i2 <- gauss_quad(g, lower = -Inf, upper = Inf, kind = 'hermite.h',
                 normalized = FALSE, mu = 2, sigma = 1)
i2 <- i2/sqrt(pi)
i2


#----------------------------------------------------------------------------

Run the code above in your browser using DataLab