statmod (version 1.0.8)

gauss.quad.prob: Gaussian Quadrature with Probability Distributions

Description

Calculate nodes and weights for Gaussian quadrature in terms of probability distributions.

Usage

gauss.quad.prob(n,dist="uniform",l=0,u=1,mu=0,sigma=1,alpha=1,beta=1)

Arguments

n
number of nodes and weights
dist
distribution that Gaussian quadrature is based on, one of "uniform", "normal", "beta" or "gamma"
l
lower limit of uniform distribution
u
upper limit of uniform distribution
mu
mean of normal distribution
sigma
standard deviation of normal distribution
alpha
positive shape parameter for beta or gamma distribution
beta
positive scale parameter for gamma distribution

Value

  • A list containing the components
  • nodesvector of values at which to evaluate the function
  • weightsvector of weights to give the function values

Details

This is a rewriting and simplification of gauss.quad in terms of probability distributions. The expected value of f(X) is approximated by sum(w*f(x)) where x is the vector of nodes and w is the vector of weights. The approximation is exact if f(x) is a polynomial of order no more than 2n+1. The possible choices for the distribution of X are as follows: Uniform on (l,u). Normal with mean mu and standard deviation sigma. Beta with density x^(alpha-1)*(1-x)^(beta-1)/B(alpha,beta) on (0,1). Gamma with density x^(alpha-1)*exp(-x/beta)/beta^alpha/gamma(alpha).

References

Golub, G. H., and Welsch, J. H. (1969). Calculation of Gaussian quadrature rules. Mathematics of Computation 23, 221-230. Golub, G. H. (1973). Some modified matrix eigenvalue problems. Siam Review 15, 318-334. Stroud and Secrest (1966). Gaussian Quadrature Formulas. Prentice- Hall, Englewood Cliffs, N.J.

See Also

gauss.quad, integrate

Examples

Run this code
out <- gauss.quad.prob(10,"normal")
sum(out$weights * out$nodes^4)
#  the 4th moment of the standard normal is 3

out <- gauss.quad.prob(32,"gamma",alpha=5)
sum(out$weights * log(out$nodes))
#  the expected value of log(X) where X is gamma is digamma(alpha)

Run the code above in your browser using DataCamp Workspace