Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

kde

Kernel Density and Distribution Estimation


Description

To compute the non-parametric kernel estimation of the probability density function (PDF) and cumulative distribution function (CDF).

Usage

kde(x, h, xgrid, ngrid, kernel = c("epan", "unif", "tria", "quar", 
    "triw", "tric", "gaus", "cos"), plot = FALSE)

Arguments

x

a numeric vector of data values.

h

the smoothing bandwidth. See 'Details' of the default bandwidth.

xgrid

the user-defined data points at which the PDF and CDF are to be evaluated. The default is the data values x.

ngrid

the number of equally spaced points at which the PDF and CDF are to be evaluated. The default is NULL.

kernel

a character string which determines the smoothing kernel function. This must be one of "unif" (uniform), "tria" (triangular), "epan" (epanechnikov), "quar" (quartic), "triw" (triweight), "tric" (tricube), "gaus" (gaussian) and "cos" (cosine). The default is "epan".

plot

a logical indicating whether to plot the estimated PDF and CDF graphs.

Details

Kernel density and distribution estimation is a non-parametric method to estimate the probability density function (PDF) and cumulative distribution function (CDF) by using kernel function for a continuous random variable. The default smoothing bandwidth is the plug-in optimal one in Fan and Gijbels (1996), i.e., h = c*n^(-1/5), where the constant is replaced by (8*pi/3)^(1/5)*2.0362*(((quantile(x, 0.75) - quantile(x, 0.25))/1.349)^(2/3)) in this function. Missing values have been removed.

Value

x

the original data values.

xgrid

the points where the PDF and CDF are to be evaluated.

fhat

the estimated PDF values at the specified points.

Fhat

the estimated CDF values at the specified points.

bw

the smoothing bandwidth used.

Warning

The smoothing bandwidth is always a critical issue in non-parametric statistics. The default smoothing bandwidth suggested by Fan and Gijbels (1996) may not perform the best in some cases. You are recommended to provide one obtained by other methods.

Author(s)

Debin Qiu <debinqiu@uga.edu>

References

Fan, I. Gijbels (1996). Local Polynomial Modeling and its Applications. Chapman & Hall, London. pp. 47.

Wand, M. P. and Jones, M. C. (1995). Kernel Smoothing. Chapman and Hall, London.

Examples

x <- rnorm(200,2,3)
# with default bandwidth
kde(x, kernel = "quar", plot = TRUE)

# with specified bandwidth
kde(x, h = 4, kernel = "quar", plot = TRUE)

snpar

Supplementary Non-parametric Statistics Methods

v1.0
GPL (>= 2)
Authors
Debin Qiu
Initial release
2014-08-11

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.