Learn R Programming

kernopt (version 1.0.0)

estim_kernel: Discrete Kernel Density Estimator

Description

Discrete Kernel Density Estimator

Usage

estim_kernel(
  kernel = c("optimal", "triang", "epanech", "binomial"),
  x,
  h,
  v,
  k = NULL
)

Value

The estimated discrete kernel density values

Arguments

kernel

the type of kernel. Currently supported kernels are limited to: "optimal", "triang", "epanech" and "binomial"

x

the list of target points at which the density is calculated

h

the bandwidth (or smoothing parameter)

v

the vector of observations

k

Optional: the integer (positive) parameter that defined the support of the kernel function (corresponds to parameter 'a' for triangular kernel). It is only used for optimal and triangular kernel

Examples

Run this code
n <- 250
mu <- 2 # Mean
x <- 0:10 # target values
y <- sort(rpois(n, mu)) # simulated Poisson observations
# kernel parameters
kernel <- "optimal"
k <- 1
# Cross Validation
H <- seq((max(y) - min(y)) / 200, (max(y) - min(y)) / 2, length.out = 50)
hcv <- cv_bandwidth(kernel = kernel, y, h = H, k = k)
# Kernel estimation
fn_opt_k <- estim_kernel(kernel = kernel, x = x, h = hcv, v = y, k = k)

Run the code above in your browser using DataLab