Learn R Programming

spatstat.geom (version 3.2-9)

integral.density: Compute Integral of One-Dimensional Kernel Density Estimate.

Description

Compute the integral of a kernel density estimate over a specified range.

Usage

# S3 method for density
integral(f, domain = NULL, weight=NULL, ...)

Value

A single numerical value.

Arguments

f

A one-dimensional probability density estimate (object of class "density") obtained from the function density.default or from unnormdensity.

domain

Optional. Range of values of the argument \(x\) over which the density \(f(x)\) should be integrated. A numeric vector of length 2 giving the minimum and maximum values of \(x\). Infinite limits are permitted.

weight

Optional. A function(x) specifying a weight integrand.

...

Ignored.

Author

Adrian Baddeley Adrian.Baddeley@curtin.edu.au.

Details

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.

See Also

density.default

quantile.density, CDF.density in package spatstat.explore

Examples

Run this code
  x <- runif(10)
  d <- density(x, bw=0.1)
  integral(d) # should be approximately 1
  integral(d, domain=c(-Inf, 0)) # mass on negative half-line
  ## mean of density
  integral(d, weight=function(x) x)

Run the code above in your browser using DataLab