Predicted values from a local polynomials of degree less than 2.
Missing values are not allowed.
npregress(x, y, criterion="rmse", bandwidth=NULL,kernel="g",
control.par=list(), cv.options=list())Returns an object of class npregress which is a list including:
The kernel bandwidth smoothing parameter.
Vector of residuals.
Vector of fitted values.
The effective degree of freedom of the smoother.
A list containing four components: x contains the
initial explanatory variables, y contains the
initial dependant variables,
criterion contains the chosen criterion, kernel the
kernel and degree the chosen degree
either a named list containing the bandwidth search
grid and all the criteria (rmse and mae) evaluated on the
grid gridbw. If the bandwidth
bandwidth is given by the user NULL is returned
A numeric vector of explanatory variable of length n.
A numeric vector of variable to be explained of length n.
Character string. If the bandwidth
(bandwidth) is missing or
NULL the number of iterations is chosen using
criterion. The criterion available is (cross-validated) rmse
("rmse") and mean (relative) absolute error.
The kernel bandwidth smoothing parameter (a numeric vector of either length 1).
Character string which allows to choose between gaussian kernel
("g"), Epanechnikov ("e"), uniform ("u"),
quartic ("q").
A named list that control optional parameters. The
two components are bandwidth for compatibility with ibr
arguments and degree which controls the degree of the local
polynomial regression. If argument bandwidth is not null or missing, its
value is used instead control.par$bandwidth. degree must
be smaller than 2. For (gaussian binned) local polynomial see
locpoly
A named list which controls the way to do cross
validation with component gridbw,
ntest, ntrain, Kfold, type,
seed, method and npermut. gridbw is
numeric vector which contains the search grid for optimal bandwidth (default
to 1/n*(1+1/n)^(0:kmax), with kmax=floor(log(n*diff(range(x))/3)/log(1+1/n))). ntest is the number of observations in test set and
ntrain is the number of observations in training set. Actually,
only one of these is needed the other can be NULL or missing. Kfold a boolean or an integer. If
Kfold is TRUE then the number of fold is deduced from
ntest (or ntrain). type is a character string in
random,timeseries,consecutive, interleaved
and give the type of segments. seed controls the seed of
random generator. npermut is the number of random draws. If
cv.options is list(), then component ntest is set to
1, type is consecutive, Kfold is TRUE, and
the other components are NULL, which leads to leave-one-out
cross-validation.
Pierre-Andre Cornillon, Nicolas Hengartner and Eric Matzner-Lober.
Wand, M. P. and Jones, M. C. (1995). Kernel Smoothing. Chapman and Hall, London.
predict.npregress,
summary.npregress,
locpoly, ibr
f <- function(x){sin(5*pi*x)}
n <- 100
x <- runif(n)
z <- f(x)
sigma2 <- 0.05*var(z)
erreur <- rnorm(n,0,sqrt(sigma2))
y <- z+erreur
res <- npregress(x,y,bandwidth=0.02)
summary(res)
ord <- order(x)
plot(x,y)
lines(x[ord],predict(res)[ord])
Run the code above in your browser using DataLab