
The kedd package (version 2.0.2) provides nonparametric
kernel smoothing tools for R:
kernel estimation of a density and of its derivatives of any
order r, kernel functions, their derivatives and convolutions,
and nine data-driven bandwidth selectors. Results are S4 objects with
ggplot2 graphics; the \(O(n^2)\)
criteria run in C++ (Rcpp) with OpenMP.
Authors: Arsalane Chouaib Guidoum (author, maintainer) and Amel Henider (author), with Iago Giné-Vázquez (contributor) — see Authors.
| Kernel | Formula | Support | r max |
|---|---|---|---|
| Gaussian | \(K(x) = \frac{1}{\sqrt{2\pi}} e^{-x^2/2}\) | \((-\infty, +\infty)\) | any |
| Epanechnikov | \(K(x) = \frac{3}{4}(1-x^2)\) | \([-1, 1]\) | 2 |
| Uniform | \(K(x) = \frac{1}{2}\) | \([-1, 1]\) | 0 |
| Triangular | \(K(x) = 1-\lvert x\rvert\) | \([-1, 1]\) | 1 |
| Biweight | \(K(x) = \frac{15}{16}(1-x^2)^2\) | \([-1, 1]\) | 4 |
| Triweight | \(K(x) = \frac{35}{32}(1-x^2)^3\) | \([-1, 1]\) | 6 |
| Tricube | \(K(x) = \frac{70}{81}(1-\lvert x\rvert^3)^3\) | \([-1, 1]\) | 9 |
| Cosine | \(K(x) = \frac{\pi}{4}\cos\left(\frac{\pi x}{2}\right)\) | \([-1, 1]\) | any |
| Silverman | \(K(x) = \frac{1}{2}e^{-\lvert x\rvert/\sqrt{2}}\sin\left(\frac{\lvert x\rvert}{\sqrt{2}}+\frac{\pi}{4}\right)\) | \((-\infty, +\infty)\) | any |
| Logistic | \(K(x) = \frac{e^{-x}}{(1+e^{-x})^2} = \frac{1}{4}\mathrm{sech}^2(x/2)\) | \((-\infty, +\infty)\) | 20 |
| Pow(s,t) | \(K(x) = c_{s,t}(1-\lvert x\rvert^s)^t\), \(c_{s,t} = \frac{s}{2B(1/s,\,t+1)}\) | \([-1, 1]\) | \(\min(st, 16)\) |
Kernels with support \([-1, 1]\) are
zero outside it. “r max” is the highest derivative order with \(K^{(r)} \ne 0\) (kernel.fun(),
kernel.conv(), dkde()); for Pow(s,t) it is
\(\min(st, 16)\) when \(s\) and \(t\) are integers and 16 otherwise. The
selectors have lower limits, given in Maximum derivative order.
The power family is passed as kernel = "pow(s,t)" (or
kernel.pow(s, t)) and contains uniform
pow(s,0), triangular pow(1,1), Epanechnikov
pow(2,1), biweight pow(2,2), triweight
pow(2,3) and tricube pow(3,3). Any \(s > 0\), \(t
\ge 0\) is allowed; derivatives up to order 16 are computed
exactly and the constants \(\mu_2(K)\),
\(\mu_4(K)\), \(R(K)\) come from Beta functions. Logistic
derivatives are available up to order 20.
| Function | Method | Derivative order r | Reference |
|---|---|---|---|
h.amise |
Asymptotic MISE rule (normal reference) | 0, 1, 2, … (max: see below) | Wand & Jones (1995) |
h.ucv |
Unbiased (least-squares) Cross-Validation | 0, 1, 2, … (max: see below) | Rudemo (1982), Bowman (1984) |
h.bcv |
Biased Cross-Validation (BCV1, BCV2) | 0, 1, 2, … (max: see below) | Scott & Terrell (1987) |
h.ccv |
Complete Cross-Validation | 0, 1, 2, … (max: see below) | Jones & Kappenman (1992) |
h.mcv |
Modified Cross-Validation | 0, 1, 2, … (max: see below) | Stute (1992) |
h.tcv |
Trimmed Cross-Validation | 0, 1, 2, … (max: see below) | Feluch & Koronacki (1992) |
h.scv |
Smoothed Cross-Validation (Gaussian kernel) | 0, 1, 2, … (no limit) | Hall, Marron & Park (1992) |
h.pcv |
Partitioned Cross-Validation (UCV, TCV, MCV, CCV, BCV1 or BCV2 in
m subsamples, nrep partitions) |
as the criterion | Marron (1987) |
h.mlcv |
Maximum-Likelihood Cross-Validation | 0 only | Habbema et al. (1974), Duin (1976) |
With the Gaussian kernel every order r is allowed; with the other kernels r is limited by the regularity of the kernel, as given in the table Maximum derivative order r below.
All selectors return an S4 object of class bandwidth;
the search interval is [0.01 * hos, 2 * hos] by default,
hos being the over-smoothing bandwidth.
The regularity \(q\) of a kernel is
the largest \(m\) such that the
pointwise derivative \(K^{(m)}\) is the
derivative of \(K\) in the sense of
distributions (\(K^{(m-1)}\) absolutely
continuous). For \(m > q\), \(K^{(m)}\) misses the Dirac masses at the
jumps of \(K^{(q)}\), and a criterion
that evaluates it at the pairwise differences no longer estimates its
target. Each criterion therefore restricts \(r\): \(r \le
q\) for dkde and h.amise, \(2r \le q\) for UCV and TCV (\(K^{(2r)}\)), \(2r
+ 2 \le q\) for MCV, \(r + 2 \le
q\) for BCV1 (convolution of \(K^{(r+2)}\)) and \(2r + 4 \le q\) for BCV2 and CCV. \(K^{(r)}\) (\(K^{(r+2)}\) for BCV1) must also be square
integrable, and the selectors are capped at \(r = 8\) (logistic) and \(r = 6\) (Pow), the derivative orders
implemented being 20 and 16. Above the limit the selectors return
h = NA with a warning, and dkde() gives a
warning; “—” means not available even at \(r =
0\):
| kernel | \(q\) | dkde |
h.amise |
h.ucv,
h.tcv |
h.mcv |
BCV1 | BCV2, h.ccv |
|---|---|---|---|---|---|---|---|
gaussian |
\(\infty\) | any | any | any | any | any | any |
logistic |
\(\infty\) | 20 | 8 | 8 | 8 | 8 | 8 |
silverman |
3 | 3 | (*) | 1 | (*) | (*) | (*) |
triweight, tricube |
3 | 3 | 3 | 1 | 0 | 1 | — |
biweight |
2 | 2 | 2 | 1 | 0 | 0 | — |
epanechnikov, triangular,
cosine |
1 | 1 | 1 | 0 | — | — | — |
uniform |
0 | 0 | 0 | 0 | — | — | — |
() The Silverman kernel is of order 4 (\(\mu_2(K) = 0\)): h.amise()
returns the value of the Gaussian kernel with a warning, and BCV1, BCV2,
MCV and CCV, built on the bias expansion of a second-order kernel, are
not defined for it. For pow(s,t), \(q = \lceil t + 1 \rceil - 1\) (\(q = t\) for an integer \(t\)) from \(|x| =
1\), and \(q = \lceil s + 1 \rceil -
1\) from \(x = 0\) unless \(s\) is an even integer; \(q\) is the smaller of the two. For example
pow(2,4): \(q = 4\) and 4,
4, 2, 1, 2, 0; pow(1.5,2.5): \(q
= 2\) and 1, 1, 1, 0, —, —. h.scv (Gaussian kernel)
has no limit and h.mlcv is for \(r = 0\) only; h.pcv has the
limits of its criterion. The same table is in ?kedd
(section Maximum derivative order*).
kernel.fun() — evaluate \(K^{(r)}(x)\) → S4 class kfun
with show() and plot()kernel.conv() — evaluate \((K^{(r)} * K^{(r)})(x)\) → S4 class
kconvkernel.pow(s, t) — name of a Pow(s,t) kernel, usable in
every functiondkde() — kernel density (or derivative) estimate → S4
class dkdebandwidth
with show() and plot()lines(bw) returns a layer:
plot(bw1)$plot + lines(bw2)# Released version 2.0.2 on CRAN
install.packages("kedd")
# Development version from GitHub
# install.packages("remotes")
remotes::install_github("ac-guidoum/kedd", build_vignettes = TRUE)
# Version 2.0.2 from the source tarball
install.packages("kedd_2.0.2.tar.gz", repos = NULL, type = "source")
# or from the source directory
devtools::install("path/to/kedd_2.0.2")Building from source compiles C++ code: on Windows this needs Rtools.
library(kedd)
x <- rnorm(500)
# Kernel density estimate (bandwidth chosen by UCV when h is missing)
d <- dkde(data = x, kernel = "gaussian")
plot(d)
# First derivative with its own bandwidth
h1 <- h.scv(x, deriv.order = 1)
plot(dkde(data = x, h = h1@h, deriv.order = 1))
# Bandwidth selectors
h.ucv(x) # unbiased CV
h.bcv(x) # biased CV
h.scv(x) # smoothed CV (Gaussian kernel)
h.pcv(x, m = 2) # partitioned CV (UCV in 2 subsamples)
# Kernel function evaluation
kf <- kernel.fun(kernel = "epanechnikov", deriv.order = 1L)
plot(kf)
# Logistic and Pow(s,t) kernels
h.ucv(x, kernel = "logistic")
h.bcv(x, kernel = kernel.pow(2, 4)) # same as kernel = "pow(2,4)"
plot(kernel.fun(kernel = "pow(1.5,2.5)", deriv.order = 1L))
# Overlay two CV curves (ggplot2)
p <- plot(h.ucv(x))
p$plot + lines(h.bcv(x))Five samples of size 200 from the Marron & Wand (1992) normal
mixtures, with known true densities (see ?"kedd-data"):
| Dataset | Marron & Wand density |
|---|---|
kurtotic |
#4 kurtotic unimodal: \(\frac23 N(0,1) + \frac13 N(0, 0.1^2)\) |
outlier |
#5 outlier: \(\frac1{10} N(0,1) + \frac9{10} N(0, 0.1^2)\) |
bimodal |
#7 separated bimodal: \(\frac12 N(-1.5, 0.5^2) + \frac12 N(1.5, 0.5^2)\) |
trimodal |
#9 trimodal: \(\frac9{20} N(-1.2, 0.6^2) + \frac9{20} N(1.2, 0.6^2) + \frac1{10} N(0, 0.25^2)\) |
claw |
#10 claw: \(\frac12 N(0,1) + \sum_{l=0}^{4}\frac1{10} N(l/2-1, 0.1^2)\) |
h.mcv(claw)
plot(dkde(data = bimodal, h = h.ucv(bimodal, deriv.order = 1)@h, deriv.order = 1))A two-page summary of the package is available in cheatsheet/kedd-cheatsheet.pdf
(source: cheatsheet/kedd-cheatsheet.html).
vignette("kedd", package = "kedd") # theory, kernels, estimators, selectors, examples
demo(package = "kedd") # list of demos
demo("kedd", package = "kedd") # quick tour
demo("kernels", package = "kedd") # kernels, derivatives, convolutions, Pow(s,t)
demo("bandwidths", package = "kedd") # all selectors compared on a bimodal sampleThe testthat suite (≈1,850 expectations) covers every
selector × kernel, the nthreads behaviour, the content of
every ggplot2 figure (plot(), lines()), the
datasets and input validation. It checks every kernel constant (\(\mu_2\), \(\mu_4\), \(R(K^{(r)})\)), convolution and derivative,
for every kernel and every implemented order, against numerical
integration, and checks Pow(s,t) against the named kernels it
generalises (identical kernels, convolutions and bandwidths).
Line coverage measured with covr
(tests only): 99.2 % overall.
| File | Coverage | File | Coverage |
|---|---|---|---|
src/kedd.cpp |
99.5 % | R/h.mlcv.R |
100 % |
R/bandwidth-class.R |
99.1 % | R/h.pcv.R |
95.7 % |
R/dkde.R |
97.8 % | R/h.scv.R |
100 % |
R/h.amise.R |
100 % | R/h.tcv.R |
100 % |
R/h.bcv.R |
100 % | R/h.ucv.R |
100 % |
R/h.ccv.R |
100 % | R/kernel.fun.R |
98.3 % |
R/h.mcv.R |
100 % | R/utils.R |
97.9 % |
cv <- covr::package_coverage("path/to/kedd_2.0.2", type = "tests")
covr::percent_coverage(cv) # 99.2
covr::report(cv) # line-by-line HTML report
source("data-raw/benchmark.R") # execution time of every functionCRAN downloads of kedd from the RStudio/Posit CRAN
mirror, obtained with cranlogs
(daily counts since the first release in August 2013) and cross-checked
with dlstats
(monthly counts; identical on the 70 months both cover, Jan 2021 – Oct
2026).
| Statistic (as of 19 Nov 2026) | Value |
|---|---|
| Total downloads (Aug 2013 – Nov 2026) | 66,708 |
| Last month | 735 |
| Last week | 301 |
| Monthly mean / median | 417 / 298 |
| Best month | Sep 2025 (1,776) |
| Year | 2013* | 2014 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020 | 2021 | 2022 | 2023 | 2024 | 2025 | 2026* |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Downloads | 586 | 2,472 | 3,872 | 2,818 | 2,918 | 3,856 | 7,657 | 12,813 | 10,566 | 4,844 | 743 | 3,462 | 6,260 | 3,841 |
* partial years (from Aug 2013; to 19 Nov 2026). The badges above are live; the figures in this section are a snapshot.
library(cranlogs)
sum(cran_downloads("kedd", from = "2013-08-01", to = Sys.Date() - 1)$count) # total
cran_downloads("kedd", when = "last-month")
library(dlstats)
x <- cran_stats("kedd") # monthly downloads
plot_cran_stats("kedd")The figure and the numbers are regenerated with
source("data-raw/downloads.R").
| Name | Role | Contact |
|---|---|---|
| Arsalane Chouaib Guidoum | author, maintainer | acguidoum@univ-tam.dz · ORCID 0000-0003-3781-2160 |
| Amel Henider | author | amel.henider@univ-tam.dz |
| Iago Giné-Vázquez | contributor | iago.gin-vaz@protonmail.com · ORCID 0000-0002-6725-2638 |
Source code: https://github.com/ac-guidoum/kedd · bug reports and suggestions: https://github.com/ac-guidoum/kedd/issues.
To cite the package (citation("kedd")):
Guidoum, A. C. (2020). Kernel estimator and bandwidth selection for density and its derivatives: the kedd package. arXiv:2012.06102. https://doi.org/10.48550/arXiv.2012.06102