integrate_primitive: Primitive Integration

Description Usage Arguments Details Value See Also

View source: R/integrate_primitive.R

Description

integrate_primitive integrates an in the mathematical sense integrable function over a compact interval using a basic step-function approximation.

Usage

1
2
3
4
5
6
7
integrate_primitive(
  integrand,
  lower,
  upper,
  subdivisions = 1000L,
  check = FALSE
)

Arguments

integrand

a R function taking a single numeric argument and returning a numeric vector of the same length. Further the function should be integrable in the mathematical sense.

lower

finite numerical scalar; the lower bound for the integration.

upper

finite numerical scalar; the upper bound for the integration.

subdivisions

positive numerical scalar; the number of evaluation points used in the procedure.

check

logical; if TRUE activate the collection of an additional measure of convergence.

Details

The KDE package has to frequently handle functions, which are integrable in the mathematical sense but are hard to integrate consistently using the base R function integrate and equivalent choices. The typical integration methods often fail for non-smooth functions or functions with a support consisting of multiple narrow disjoint intervals.

Since the function to integrate is often computationally cheap to evaluate, approximating the function on a narrow grid and integrating the approximation as primitive function yields a practical approach.

integrate_primitive makes use of this approach. The support has to be finite to allow for a discretisation grid. In particular lower and upper must be finite. The number of evaluation points is specified in the positive numerical parameter subdivisions. In particular a higher number of subdivisions yields a more accurate result at the expense of longer runtimes. Points at which the integrand takes non-finite values will be ignored by the primitive approximation.

The check parameter can be set to enable the collection of an additional measure of convergence rel_error. The relative error is calculated by computing the integral for increasing numbers of subdivisions and comparing the successive results.

Value

integrate_primitive returns a named list containing the entries value and rel_error for the integration value and relative error respectively. If the check parameter is not set rel_error will always be equal to NULL.

See Also

IntegrableFunction as application example for integrate_primitive.


hericks/KDE documentation built on Aug. 22, 2020, 12:04 a.m.