Keywords - Function groups - @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

Library: smoother
See also: denbwcrit denxbwcrit denbwsel denrot Rdenbest

Quantlet: denbbwcrit
Description: This is a variant of denxbwcrit and denbwcrit using linear binning for fast computation. All kernel estimates of the integrated squared densities or density derivatives are computed approximately by Rdenbest which uses linear binning.

Reference(s):

Usage: {hopt, ch} = denbbwcrit(crit, x ,h {,K} {,d})
Input:
crit string, criterion for bandwidth selection: "lscv" = Least Squares Cross Validation, "bcv" = Biased Cross Validation, "scv" = Smoothed Cross Validation, "jmp" = Jones, Marron and Park Cross Validation, "pm" = Park and Marron Plug-in, "sj" = Sheather and Jones Plug-in
x n x 1 vector, the data
h p x 1 vector, bandwidth grid
K optional string, represents the kernel function, default = "gau"
d optional scalar, discretization bin width. d must be smaller than min(h). If not given, the minimum of min(h)/3 and (max(x)-min(x))/200 is used.
Output:
hopt scalar, optimal bandwidth (If negative in case of "pm" or "sj", denbwcrit needs to be run again with a different range of h.)
ch p x 2 vector, the criterion function at values h

Note:

Example:
library("smoother")
library("xplore")
randomize(0)
n = 300
crit = "sj"
{w,mu,sig}=normalmixselect("Marron_Wand_6")
x = normalmix(n,w,mu,sig)
x = round(x,1)
d = 0.1
h = grid(0.2, 0.01, 20)
; compute opt bw: binned, warped, and exact
{hoptb, chb} = denbbwcrit(crit,x,h,d)
{hopt, ch} = denbwcrit(crit,x-d/2,h,d)
{hoptx, chx} = denxbwcrit(crit,x,h)
; show criterion function and optimal bw
chb~chx~ch
hoptb~hoptx~hopt

Result:
Computes the optimal bandwidth and the criterion function
for rounded data; denbbwcrit (columns one and two), denbwcrit
(columns three and four) and denxbwcrit (columns five and six)
yield the same results. If the data are not rounded,
the results are still approximately equal and the accuracy
can be increased by reducing the bin width d.

Contents of _tmp
[ 1,]      0.2  0.024196      0.2  0.024196      0.2  0.024196
[ 2,]     0.21  0.019418     0.21  0.019418     0.21  0.019418
[ 3,]     0.22  0.014284     0.22  0.014284     0.22  0.014284
[ 4,]     0.23  0.0088378     0.23  0.0088378     0.23  0.0088378
[ 5,]     0.24  0.0031245     0.24  0.0031245     0.24  0.0031245
[ 6,]     0.25 -0.0028118     0.25 -0.0028118     0.25 -0.0028118
...

Contents of _tmp
[1,]  0.24526  0.24526  0.24526
Example:
library("smoother")
library("xplore")
library("plot")
n = 4000
example = "Marron_Wand_9"
h = grid(0.01, 0.02, 25) ; bandwidth grid
xgrid = grid(-3.1, 0.05, 125) ; appropriate for MW examples
; generate variates
{w, mu, sigma} = normalmixselect(example)
x = normalmix(n, w, mu, sigma)
; find bandwidths using binned approximation
{hopt, ch} = denbbwcrit("sj", x, h)
hrot = denrot(x, "gau")
hopt~hrot
; compute density estimates
fh1 = denxest(x, hrot, "gau", xgrid)
fh2 = denxest(x, hopt, "gau", xgrid)
fx = normalmixdens(xgrid, w, mu, sigma)
; plotting
disp = createdisplay(2,2)
p1 = setmask(ch, "line", "green")
p2 = setmask(fx, "line", "thin", "red")
p3 = setmask(fh1, "line", "blue")
p4 = setmask(fh2, "line", "blue")
show(disp, 1, 2, p1, gryline(0, h))
show(disp, 1, 1, p2)
show(disp, 2, 1, p2, p3)
show(disp, 2, 2, p2, p4)
setgopt(disp,1,1,"title",string("Example: %s",example))
setgopt(disp,1,2,"title","SJ-criterion function")
setgopt(disp,2,1,"title",string("KDE with h_NR = %f", hrot))
setgopt(disp,2,2,"title",string("KDE with h_SJ = %f", hopt))

Result:
Shows a graphic with four windows representing: the bimodal
normal mixture density, the criterion function of the
Sheather-and-Jones bandwidth selector, a KDE using Silverman's
normal reference bandwidth, and a KDE using the optimal
Sheather-and-Jones one. Linear binning is used for fast computation.

Contents of _tmp
[1,]  0.16804  0.25697



Author: J.-U. Scheer, 20020915 license MD*Tech
(C) MD*TECH Method and Data Technologies, 05.02.2006