Skip to contents

Computes f-hat(x) equal to one over n times h times the sum over i of K of (x minus X_i) divided by h.

Usage

kde(x, x_eval, bandwidth, kernel_type = KERNEL_GAUSSIAN)

Arguments

x

Numeric data vector.

x_eval

Evaluation grid.

bandwidth

Positive bandwidth.

kernel_type

Integer code or kernel name.

Value

Numeric vector of estimated densities.

References

Silverman, B. W. (1986). Density Estimation for Statistics and Data Analysis. Chapman and Hall.

Examples

set.seed(1)
x <- sort(runif(40, -2, 2))
x_eval <- seq(-1.5, 1.5, length.out = 20)
d <- kde(x, x_eval, bandwidth = 0.4, kernel_type = "epanechnikov")
d
#>  [1] 0.2309826 0.2779303 0.3079858 0.2703979 0.1968256 0.2729060 0.3136762
#>  [8] 0.3266018 0.2971079 0.1804394 0.1791379 0.1908009 0.2300002 0.3118557
#> [15] 0.3198503 0.3239973 0.2746146 0.2398812 0.2357952 0.2418524