densityfun: Kernel density estimation

Description Usage Arguments Value Author(s) See Also Examples

View source: R/densityfun.R

Description

Return a function performing kernel density estimation. The difference between density and densityfun is similar to that between approx and approxfun.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
densityfun(
  x,
  bw = "nrd0",
  adjust = 1,
  kernel = "gaussian",
  weights = NULL,
  window = kernel,
  width,
  n = 512,
  from,
  to,
  cut = 3,
  na.rm = FALSE,
  ...
)

Arguments

x

numeric. The data from which the estimate is to be computed.

bw

numeric. The smoothing bandwidth to be used. See the eponymous argument of density.

adjust

numeric. The bandwidth used is actually adjust*bw. This makes it easy to specify values like 'half the default' bandwidth.

kernel, window

character. A string giving the smoothing kernel to be used. Authorized kernels are listed in .kernelsList(). See also the eponymous argument of density.

weights

numeric. A vector of non-negative observation weights, hence of same length as x. See the eponymous argument of density.

width

this exists for compatibility with S; if given, and bw is not, will set bw to width if this is a character string, or to a kernel-dependent multiple of width if this is numeric.

n

The number of equally spaced points at which the density is to be estimated. See the eponymous argument of density.

from, to

The left and right-most points of the grid at which the density is to be estimated; the defaults are cut * bw outside of range(x).

cut

By default, the values of from and to are cut bandwidths beyond the extremes of the data. This allows the estimated density to drop to approximately zero at the extremes.

na.rm

logical. If TRUE, missing values are removed from x. If FALSE any missing values cause an error.

...

Additional arguments for (non-default) methods.

Value

A function that can be called to generate a density.

Author(s)

Adapted from the density function of package stats. The C code of BinDist is copied from package stats and authored by the R Core Team with contributions from Adrian Baddeley.

See Also

density and approxfun from package stats.

Examples

1
2
3
x <- rlnorm(1000, 1, 1)
f <- densityfun(x, from = 0)
curve(f(x), xlim = c(0, 20))

statip documentation built on Nov. 18, 2019, 1:06 a.m.