Calculate local likelihood kernel weights.

KernWeight(x, x0, band, kernel = KernEpa, band_type = "constant")

Arguments

x

Vector of observed covariate values.

x0

Scalar covariate value at which local likelihood estimation is performed.

band

Kernel bandwidth parameter (positive scalar). See Details.

kernel

Kernel function to use. Should accept a numeric vector parameter and return a non-negative numeric vector of the same length. See KernFun().

band_type

A character string specifying the type of bandwidth: either "constant" or "variable". See Details.

Value

A vector of nonnegative kernel weights of the same length as x.

Details

For the constant bandwidth of size band = h, the weights are calculated as

wgt = kernel((x-x0) / h) / h

where kernel is the kernel function. For bandwidth type "variable", a fixed fraction band of observations is used, i.e,

h = sort( abs(x-x0) )[ floor(band*length(x)) ]

Examples

x <- sort(runif(20))
x0 <- runif(1, min = min(x), max= max(x))
KernWeight(x, x0, band=0.3, kernel = KernEpa, band_type = "constant")
#>  [1] 0.0000000 0.0000000 0.5231907 0.9669443 1.0612962 1.2444669 2.4575241
#>  [8] 2.4989902 2.3342279 1.3003913 1.1008385 0.8895873 0.7857324 0.0000000
#> [15] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
KernWeight(x, x0, band=0.3, kernel = KernEpa, band_type = "variable")
#>  [1] 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.41957430
#>  [7] 3.19822658 3.29320975 2.91580212 0.54767584 0.09057621 0.00000000
#> [13] 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
#> [19] 0.00000000 0.00000000