*! version 1.0 16 Jul 2018

Title

integrate_aq -- Adaptive Gaussian quadrature for a one dimensional integrand

Syntax

integrate_aq
[,
options]

Main
lower(#) specifies the lower limit of the integral. Default value is -1.

upper(#) specifies the upper limit of the integral. Default value is 1.

function(string) specifies the function to be integrated, this must be a function of x.

quadpts(#) specifies the number of quadrature points. Default value ist 80.

vectorise specifies the function needs to be vectorised.

Description

integrate_aq is an implementation of Gaussian adaptive quadrature, indefinite integrals
are handled by using transformations onto a definite integral. Infinity limits are
represented by a full stop . The adaptive quadrature splits any single integral, into
two integrals, at the mid point. If the two integrals is not close to the overall integral
then the sub integrals are split further. By doing the sub-integrals there is some
measurement of the error in the integral. Occasionally some integrands can require many sub-integrals
and this can take a long time to get an answer and will likely result in a large error.

This command has been primarily written in the MATA language but is a Stata command. The function can be
any single line
expression and the integration is with respect to x. The text from the option function()
will be used to create a new function in Mata which is then passed to the integration algorithm.

The number of quadrature points can be chosen to be any number above 1 but the larger this number the slower the algorithm.
There is no upper limit because the quadrature points are chosen by calculating the eigenvalues and eigenvectors
of a companion matrix.

Options

Main

lower(#) specifies the lower limit of the integral. Default value is -1

upper(#) specifies the upper limit of the integral. Default value is 1

function(string) specifies the function to be integrated, this must be a function of x.

quadpts(int 80) specifies the number of quadrature points.

vectorise specifies the function needs to be vectorised.

Examples

The distribution functions in Mata already accept vectors as arguments so can be used in the function
directly. The following examples are all standard results that can be obtained using the cumulative distribution functions.

integrate_aq, f(normalden(x)) l(-1) u(1)

integrate_aq, f(normalden(x)) l(-1.96) u(1.96)

integrate_aq, f(normalden(x)) l(-1.96) u(.)

integrate_aq, f(normalden(x)) l(.) u(.)

An example of a user-defined function would be the polynomial x+x^2+x^3
note that because this function is not defined by the appropriate vector operations
then the option vectorise needs to be used.

integrate_aq, f(x+x^2+x^3) v l(-10) u(10)

A quicker implementation of the same function would be

integrate, f(x:+x:^2+x:^3) l(-10) u(10)

Stored results

Scalars

r(integral) The value of the integral

r(error) The size of the error associated with the integral

Author

Dr Adrian Mander, MRC Biostatistics Unit, University of Cambridge.

Email adrian.mander@mrc-bsu.cam.ac.uk

See Also

Related commands:

integrate (if installed), install by
clicking ssc install integrate