View source: R/unnormdensity.R
integral.density | R Documentation |
Compute the integral of a kernel density estimate over a specified range.
## S3 method for class 'density'
integral(f, domain = NULL, weight=NULL, ...)
f |
A one-dimensional probability density estimate
(object of class |
domain |
Optional. Range of values of the argument |
weight |
Optional. A |
... |
Ignored. |
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.
A single numerical value.
.
density.default
quantile.density
, CDF.density
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.