Learn R Programming

bda (version 1.2.7-31)

bandwidth: Bandwidth Selectors for Kernel Density Estimation for Weighted Data

Description

Bandwidth selectors for Gaussian kernels in wkde.

Usage

bw.wnrd0(x,w,n=length(x), na.rm=TRUE)

bw.wnrd(x,w,n=length(x), na.rm=TRUE)

bw.wmise(x,w,n=length(x), na.rm=TRUE)

Arguments

x
numeric vector.
w
The weights of x. The weight w_i of any observation x_i should be non-negative. If x_i=0, x_i will be removed from the analysis.
n
Sample size. Default: length of the vector x. If w is given, n could be specified to be different from the length of x.
na.rm
logical flag: if TRUE, NA values will be ignored; otherwise, the program will be halted with error information.

concept

bandwidth

Details

bw.wnrd0 implements a rule-of-thumb for choosing the bandwidth of a Gaussian kernel density estimator. It defaults to 0.9 times the minimum of the standard deviation and the interquartile range divided by 1.34 times the sample size to the negative one-fifth power (= Silverman's rule of thumb, Silverman (1986, page 48, eqn (3.31)) unless the quartiles coincide when a positive result will be guaranteed.

bw.wnrd is the more common variation given by Scott (1992), using factor 1.06.

bw.wmise implement the automatic bandwidth selector by minimizing the integrated squared error using least squares cross-validation for weighted data.

References

Scott, D. W. (1992) Multivariate Density Estimation: Theory, Practice, and Visualization. Wiley.

Sheather, S. J. and Jones, M. C. (1991) A reliable data-based bandwidth selection method for kernel density estimation. Journal of the Royal Statistical Society series B, 53, 683--690.

Silverman, B. W. (1986) Density Estimation. London: Chapman and Hall.

Venables, W. N. and Ripley, B. D. (2002) Modern Applied Statistics with S. Springer.

See Also

density.

Examples

Run this code
x <- faithful$eruptions
  size = length(x)

  xt = table(x)
  x1 = as.numeric(names(xt))
  w1 = as.numeric(xt)
  bw.wnrd0(x1, w1)
  bw.wnrd0(x1, w1, n=size)
  bw.nrd0(x)

  bw.wnrd(x1, w1)
  bw.wnrd(x1, w1, n=size)
  bw.nrd(x)
 
  out = bw.wmise(x)
  plot(out, type='l')
  
  y = rnorm(100,34.5, 1.5)
  out = bw.wmise(round(y))
  plot(out, type='l')

Run the code above in your browser using DataLab