thumbBw: Rule of thumb for bandwidth selection.

View source: R/locpol.R

thumbBwR Documentation

Rule of thumb for bandwidth selection.

Description

Implements Fan and Gijbels(1996)'s Rule of thumb for bandwidth selection

Usage

thumbBw(x, y, deg, kernel, weig = rep(1, length(y)))
compDerEst(x, y, p, weig = rep(1, length(y)))

Arguments

x

x covariate data values.

y

y response data values.

p

order of local polynomial estimator.

deg

Local polynomial estimation degree($p$).

kernel

Kernel used to perform the estimation.

weig

weights if they are required.

Details

See Fan and Gijbels(1996) book, Section 4.2. This implementation is also considering weights. compDerEst computes the p+1 derivative of the regression function in a simple manner, assuming it is a polynomial in x. thumbBw gives a bandwidth selector by means of pilot estimator given by compDerEst and the mean of residuals.

Value

thumbBw returns a single numeric value, while compDerEst returns a data frame whose components are:

x

x values.

y

y values.

res

residuals for the parametric estimation.

der

derivative estimation at x values.

Author(s)

Jorge Luis Ojeda Cabrera.

References

Fan, J. and Gijbels, I. Local polynomial modelling and its applications\/. Chapman & Hall, London (1996).

Wand, M.~P. and Jones, M.~C. Kernel smoothing\/. Chapman and Hall Ltd., London (1995).

See Also

regCVBwSelC, pluginBw.

Examples

	size <- 200
	sigma <- 0.25
	deg <- 1
	kernel <- EpaK
	xeval <- 0:100/100
	regFun <- function(x) x^3
	x <- runif(size)
	y <- regFun(x) + rnorm(x, sd = sigma)
	d <- data.frame(x, y)
	cvBwSel <- regCVBwSelC(d$x,d$y, deg, kernel, interval = c(0, 0.25))
	thBwSel <- thumbBw(d$x, d$y, deg, kernel)
	piBwSel <- pluginBw(d$x, d$y, deg, kernel)
	est <- function(bw, dat, x) return(locPolSmootherC(dat$x,dat$y, x, bw, deg,
					kernel)$beta0)
	ise <- function(val, est) return(sum((val - est)^2 * xeval[[2]]))
	plot(d$x, d$y)
	trueVal <- regFun(xeval)
	lines(xeval, trueVal, col = "red")
	xevalRes <- est(cvBwSel, d, xeval)
	cvIse <- ise(trueVal, xevalRes)
	lines(xeval, xevalRes, col = "blue")
	xevalRes <- est(thBwSel, d, xeval)
	thIse <- ise(trueVal, xevalRes)
	xevalRes <- est(piBwSel, d, xeval)
	piIse <- ise(trueVal, xevalRes)
	lines(xeval, xevalRes, col = "blue", lty = "dashed")
	res <- rbind(	bw = c(cvBwSel, thBwSel, piBwSel),
					ise = c(cvIse, thIse, piIse) )
	colnames(res) <- c("CV", "th", "PI")
	res

locpol documentation built on Nov. 29, 2022, 9:05 a.m.

Related to thumbBw in locpol...