This is a method for the generic function integral.
It computes the numerical integral
$$
I = \int f(x) dx
$$
of the density estimate f.
If weight is specified, then the weighted integral
$$
I = \int w(x) f(x) dx
$$
is computed, where \(w\) is the function specified by weight.
This function must return finite numerical values.
If domain is specified, the integral is restricted to the
interval of \(x\) values given by the domain.
Integrals are calculated numerically using the trapezoidal rule
restricted to the domain given.