denCVBwSelC: CV bandwidth selector for density

View source: R/locpol.R

denCVBwSelCR Documentation

CV bandwidth selector for density

Description

Computes Cross Validation bandwidth selector for the Parzen–Rosenblatt density estimator...

Usage

denCVBwSelC(x, kernel = gaussK, weig = rep(1, length(x)),
            interval = .lokestOptInt)

Arguments

x

vector with data points.

kernel

Kernel used to perform the estimation, see Kernels.

weig

Vector of weights for observations.

interval

A range of values where to look for the bandwidth parameter.

Details

The selector is implemented using its definition.

Value

A numeric value with the bandwidth.

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

bw.nrd0, dpik.

Examples

stdy <- function(size=100,rVar=rnorm,dVar=dnorm,kernel=gaussK,x=NULL)
{
	if( is.null(x) ) x <- rVar(size)
	Tc <- system.time( dbwc <- denCVBwSelC(x,kernel) )[3]
	ucvT <- system.time( ucvBw <- bw.ucv(x,lower=0.00001,upper=2.0) )[3]
	nrdT <- system.time( nrdBw <- bw.nrd(x) )[3]
	{
		xeval <- seq( min(x)+dbwc , max(x)-dbwc ,length=50)
		hist(x,probability=TRUE)
		lines(xeval,trueDen <- dVar(xeval),col="red")
		lines(density(x),col="cyan")
		xevalDenc <- PRDenEstC(x,xeval,dbwc,kernel)
		dencMSE <- mean( (trueDen-xevalDenc)^2 )
		xevalucvDen <- PRDenEstC(x,xeval,ucvBw,kernel)
		ucvMSE <- mean( (trueDen-xevalucvDen)^2 )
		xevalDenNrd <- PRDenEstC(x,xeval,nrdBw,kernel)
		nrdMSE <- mean( (trueDen-xevalDenNrd)^2 )
		lines(xevalDenc,col="green")
		lines(xevalucvDen,col="blue")
		lines(xevalDenNrd,col="grey")
	}
	return( cbind(  bwVal=c(evalC=dbwc,ucvBw=ucvBw,nrdBw=nrdBw),
				mse=c(dencMSE,ucvMSE,nrdMSE),
				time=c(Tc,ucvT,nrdT) ) )
}
stdy(100,kernel=gaussK)
stdy(100,rVar=rexp,dVar=dexp,kernel=gaussK)
##	check stdy with other kernel, distributions

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

Related to denCVBwSelC in locpol...