localpoly.reg(X, Y, points = NULL, bandwidth = "CV",
gridsize = 30, degree.pol = 0, kernel.type = "epanech",
deriv = 0)In cross validation, for multivariate X and bandwidth options "CV" and "GCV", the procedure searches individually for each covariate, the bandwidth that produces the smallest MSE from a grid of gridsize possible bandwidths evenly distributed between the minimum and maximum/2 distance of any of the points of that covariate. In other words, one separate cross-validation is performed in each dimension of X.
In cross validation, for multivariate X and bandwidth options "CV2" and "GCV2", a d-dimensional (number of covariates) grid is created, where each dimension of the grid is a vector of gridsize possible bandwidths evenly distributed between the minimum and maximum/2 distance of any of the points in each covariate. Then a search is done crossing all possible combinations of values of each dimension of the grid, where the resulting vector of bandwidths correspond to those which yeild minimum MSE.
Adaptive bandwidth, for univariate X only, is obtained by a similar procedure to the one proposed by Fan and Gijbels (1995). The interval is split into [1.5*n/(10*log(n))] intervals, a leave-one-out cross validation is performed in each interval to obtain a local bandwidth. These bandwidths are then smoothed to obtain the bandwidth for each point in X.
Wand M. P. and Jones M. C. (1995). Kernel Smoothing. Chapman and Hall.
npvarselec, npmodelcheck
X = rnorm(100)
Y = X^3 + rnorm(100)
localpoly.reg(X, Y, degree.pol = 0, kernel.type = "box",
bandwidth = "CV")
localpoly.reg(X, Y, degree.pol = 1, kernel.type = "box",
bandwidth = "CV")
##--
X = runif(100,-3,3)
Y = sin(1/2*pi*X) + rnorm(100,0,.5)
localpoly.reg(X, Y, degree.pol = 0, kernel.type = "gaussian",
bandwidth = "CV")
localpoly.reg(X, Y, degree.pol = 1, kernel.type = "gaussian",
bandwidth = "CV")
Run the code above in your browser using DataLab