kde | R Documentation |
Implements the (classical) kernel density estimator, see (2.2a) in Silverman (1986).
kde(xin, xout, h, kfun)
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: |
The classical kernel density estimator is given by
\hat f(x;h) = n^{-1}∑_{i=1}^n K_h(x-X_{i})
h is determined by a bandwidth selector such as Silverman's default plug-in rule.
A vector with the density estimates at the designated points xout.
R implementation and documentation: Dimitrios Bagkavos <dimitrios.bagkavos@gmail.com>
Silverman (1986), Density Estimation for Statistics and Data Analysis, Chapman and Hall, London.
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.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.