KDE: Kernel Density Estimator

KDER Documentation

Kernel Density Estimator

Description

KDE returns the probability function for the kernel density estimator

Usage

KDE(
  data,
  weights = NULL,
  bandwidth = NULL,
  df = Inf,
  density.name = "kde",
  value.name = "Value",
  discrete = FALSE,
  discrete.warn = TRUE,
  to.environment = FALSE,
  envir = .GlobalEnv
)

Arguments

data

Input data for the kernel density estimator (a numeric vector)

weights

Weights for the kernel density estimator (a numeric vector with the same length as the data)

bandwidth

Bandwidth for the KDE; if NULL it is estimated

df

Degrees-of-freedom for the T-distribution

density.name

Name of the KDE distribution; used for naming of the probability functions (a character string)

value.name

Name of the values in the data; used for naming the plot of the KDE

discrete

Logical; if TRUE the function produces a discrete KDE over the integers

discrete.warn

Logical; if TRUE the function gives a warning if non-discrete data is used to produce a discrete KDE

to.environment

Logical; if TRUE the probability functions are attached to the global environment

envir

The environment where the probability functions are loaded (if to.environment is TRUE)

Details

The kernel density estimator for a set of input data is obtained by taking a mixture distribution consisting of a (possibly weighted) combination of kernels. In this function we compute the KDE using the kernel of the T-distribution; the function can also estimate a discretised version of the KDE (taken over the integers) if required. The degrees-of-freedom and the bandwidth for the KDE can be specified in the inputs; if the bandwidth is not specified then it are estimated using the methods set out in Sheather and Jones (1991) used in the stats::density function. The output of the function is a list of class kde that contains the probability functions for the KDE and associated information. The output object can be plotted to show the density function for the KDE.

Note: The function has an option to.environment to allow the user to load the probability functions to the global environment or another specified environment. If this is set to TRUE then the probability functions are loaded to the specified environment in addition to appearing as elements of the output; there is a message informing the user if existing objects in the global environment were overwritten. If the functions are not loaded to the environment then the user can use the function KDE.load to load them later from the produced object.

Value

A kde object containing the probability functions for the kernel density estimator

Examples

k <- KDE(rnorm(500))
print(k)
plot(k)
KDE.load(k, environment()); ls()

utilities documentation built on July 1, 2022, 9:06 a.m.

Related to KDE in utilities...