gauss.quad.prob(n,dist="uniform",l=0,u=1,mu=0,sigma=1,alpha=1,beta=1)
"uniform"
, "normal"
, "beta"
or "gamma"
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)
.gauss.quad
, integrate
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 DataLab