CV_error_fun: Leave-one-out cross-validation (LOOCV) error

Description Usage Arguments Details Value Examples

View source: R/lpreba.R

Description

Leave-one-out cross-validation (LOOCV) error for a given bandwidth, either for the local polynomial estimator or the boundary-adjusted Nadaraya-Watson estimator.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
CV_error_fun(
  X,
  Y,
  kernel = epanechnikov,
  bw,
  degree = 1L,
  kernel_left = epanechnikov_left,
  boundary_left = NA,
  boundary_right = NA,
  boundary_adjustment = FALSE
)

Arguments

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.

kernel_left

Left boundary kernels (function). Default is epanechnikov_left.

boundary_left

Lower boundary of the support of X (scalar). Default is NA.

boundary_right

Upper boundary of the support of X (scalar). Default is NA.

boundary_adjustment

Explicit boundary adjustment (boolean). Default is FALSE.

Details

The LOOCV error function is the mean squared prediction errors.

Value

LOOCV error for bandwidth bw (scalar).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
#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

# Local polynomial estimator
#CV_error_fun(X = X, Y = Y, kernel = epanechnikov, bw = bw, degree = 1L,
#             kernel_left = epanechnikov_left,
 #            boundary_left = NA, boundary_right = NA,
#             boundary_adjustment = FALSE)

# Boundary-adjusted Nadaraya-Watson estimator
#CV_error_fun(X = X, Y = Y, kernel = epanechnikov, bw = bw, degree = 0L,
 #            kernel_left = epanechnikov_left,
 #            boundary_left = 0, boundary_right = 1,
  #           boundary_adjustment = TRUE)

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