Library: | smoother |
See also: | denxest denci dencb denrot denbwsel denestp |
Quantlet: | denest | |
Description: | estimates a univariate density by kernel density estimation. The computation uses WARPing. |
Usage: | fh = denest(x {,h {,K} {,d} }) | |
Input: | ||
x | n x 1 vector, the data. | |
h | scalar, bandwidth. If not given, the rule of thumb bandwidth computed by denrot is used (Silverman's rule of thumb). | |
K | string, kernel function on [-1,1] or Gaussian kernel "gau". If not given, the Quartic kernel "qua" is used. | |
d | scalar, discretization binwidth. d must be smaller than h. If not given, the minimum of h/3 and (max(x)-min(x))/100 is used. | |
Output: | ||
fh | m x 2 matrix, the first column is a grid and the second column contains the density estimate on that grid. |
library("smoother") library("plot") ; mu = 10 si = 5 x = si*normal(200)+mu ; generate data ; fh = denest(x) ; estimate density f = sort(x~pdfn((x-mu)/si)/si) ; true density ; ; fh = setmask(fh,"line","blue") f = setmask(f ,"line","black","thin") plot(f,fh) ; graph functions
The density estimate (blue) for a normal distribution with mean mu=10, standard deviation si=5 is pictured using Quartic kernel (default) and Silverman's rule-of-thumb bandwidth (default), together with the true density (thin black).
library("smoother") library("plot") ; mu = 10 si = 5 x = si*normal(200)+mu ; generate data ; fhe= denest(x,3,"epa") ; estimate density fhu= denest(x,3,"uni") ; estimate density f = sort(x~pdfn((x-mu)/si)/si) ; true density ; fhe= setmask(fhe,"line","green") fhu= setmask(fhu,"line","red") f = setmask(f ,"line","black","thin") plot(f,fhu,fhe) ; graph functions
The density estimate using the Epanechnikov kernel (green) is compared to the density estimate using the Uniform kernel (red) and the true density (thin black). In both cases, bandwidth h=3 is used.