kde {L2DensityGoFtest} | R Documentation |
Kernel Density Estimation
Description
Implements the (classical) kernel density estimator, see (2.2a) in Silverman (1986).
Usage
kde(xin, xout, h, kfun)
Arguments
xin |
A vector of data points. Missing values not allowed. |
xout |
A vector of grid points at which the estimate will be calculated. |
h |
A scalar, the bandwidth to use in the estimate, e.g. |
kfun |
Kernel function to use. Supported kernels: |
Details
The classical kernel density estimator is given by
\hat f(x;h) = n^{-1}\sum_{i=1}^n K_h(x-X_{i})
h
is determined by a bandwidth selector such as Silverman's default plug-in rule.
Value
A vector with the density estimates at the designated points xout.
Author(s)
R implementation and documentation: Dimitrios Bagkavos <dimitrios.bagkavos@gmail.com>
References
Silverman (1986), Density Estimation for Statistics and Data Analysis, Chapman and Hall, London.
Examples
x<-seq(-5, 5,length=100) #design points where the estimate will be calculated
plot(x, dnorm(x), type="l", xlab = "x", ylab="density") #plot true density function
SampleSize <- 100
ti<- rnorm(SampleSize) #draw a random sample from the actual distribution
huse<-bw.nrd(ti)
arg2<-kde(ti, x, huse, Epanechnikov) #Calculate the estimate
lines(x, arg2, lty=2) #draw the result on the graphics device.