LP: Local polynomial estimator

Description Usage Arguments Details Value References Examples

View source: R/lpreba.R

Description

Local polynomial regression estimator of arbitrary degree.

Usage

1
LP(x, X, Y, kernel = epanechnikov, bw, degree = 1L)

Arguments

x

Evaluation points (vector).

X

Data for the regressor (vector).

Y

Data for the regressand (vector).

kernel

Kernel (function). Default is epanechnikov.

bw

Bandwidth (scalar).

degree

Degree of the locally fitted polynomial (integer). Default is 1L.

Details

The degree of the local polynomial estimator can be chosen. Two special cases are the Nadaraya-Watson estimator (degree = 0L) and the local linear estimator (degree = 1L).

The most important compactly supported (on the interval [-1, 1]) kernels are available: uniform, triangular, epanechnikov, biweight, triweight, tricube, cosine.

The effective kernel at an evaluation point is the set of effectively assigned weights in the smoothing process (see e.g. Hastie and Loader, 1993).

To obtain estimates for the first derivative of the regression function, the degree has to be at least 1L. To obtain estimates for the second derivative of the regression function, the degree has to be at least 2L.

Value

List containing:

estimates

Estimates for the regression function at the evaluation points (vector).

effective_kernels

Effective kernels at the evaluation points (matrix).

slopes

Estimates for the first derivative (slope) of the regression function at the evaluation points (vector).

curvatures

Estimates for the second derivative (curvature) of the regression function at the evaluation points (vector).

References

Hastie, T. and C. Loader (1993). “Local regression: Automatic kernel carpentry”. Statistical Science 8 (2), pp. 120–129.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
m_fun <- function(x) {sin(2*pi*x)} # True regression function
n <- 100 # Sample size
X <- seq(0, 1, length.out = n) # Data for the regressor
m_X <- m_fun(X) # True values of regression function
epsilon <- rnorm(n, sd = 0.25) # Error term
Y <- m_X + epsilon # Data for the regressand
bw <- 0.2 # Bandwidth
x <- seq(0, 1, length.out = n/2) # Evaluation points

output_LP <- LP(x = x, X = X, Y = Y, kernel = epanechnikov, bw = bw, degree = 1L)
estimates_LP <- output_LP$estimates
effective_kernels_LP <- output_LP$effective_kernels
slopes_LP <- output_LP$slopes
curvatures_LP <- output_LP$curvatures # Yields only NAs since degree >= 2L is required

svjaco/lpreba documentation built on March 4, 2022, 12:42 a.m.