Choosing the bandwidth: the normal reference rule and cross-validation
Archive 2011–2014
Density estimation
Kernel methods
R
Two practical ways to pick h for a kernel density estimator: Silverman’s rule of thumb and least-squares cross-validation, with an R comparison.
Author
Maikol Solís
Published
March 18, 2012
Modified
November 30, 2026
This post belongs to a series of study notes I first published in 2012, during my PhD. I revised it in 2026: the mathematics was checked and corrected, the text rewritten, and an R example added.
The theory in the previous posts tells us how the bandwidth \(h\) should shrink with \(n\), but the optimal constant depends on the unknown density. This post covers two popular ways to choose \(h\) from the data:
the plug-in approach, in its “quick and dirty” form, the normal reference rule (Silverman 1986);
cross-validation, which minimizes an unbiased estimate of the risk.
Throughout, \(\hat f_h(x) = \frac1n\sum_i K_h(x - X_i)\) with \(K_h(u) = h^{-1}K(u/h)\), and \(K\) is a symmetric kernel.
The normal reference rule
The asymptotically optimal bandwidth for the MISE of a second-order kernel is
It depends on \(f\) through \(\int (f'')^2\). The normal reference rule pretends that \(f\) is \(N(\mu, \sigma^2)\), computes \(\int (f'')^2\) for that density, and plugs it in. For the Gaussian kernel this gives
The scale \(\sigma\) has to be estimated. A robust choice is \(\hat\sigma = \min\{s,\ Q/1.34\}\), where \(s\) is the sample standard deviation and \(Q\) the interquartile range (75th minus 25th percentile). For normal data \(Q \approx 1.34\,\sigma\), so \(Q/1.34\) estimates \(\sigma\) consistently. Taking the minimum protects against heavy tails and outliers, which inflate \(s\). Summarizing,
The rule works well when \(f\) is close to normal. For multimodal or strongly skewed densities \(\int (f'')^2\) is much larger than the normal value, and the rule oversmooths. Silverman’s popular variant replaces 1.06 by 0.9 to reduce this effect (it is R’s default bw.nrd0).
Least-squares cross-validation
Instead of assuming a shape for \(f\), cross-validation estimates the risk directly. The integrated squared error is
The first term depends only on the data. The second does not: \(\int \hat f_h f\) is the expectation of \(\hat f_h(X)\) for a new observation \(X \sim f\), independent of the sample. The naive estimate
uses each \(X_i\) twice: once to build \(\hat f_h\) and once to evaluate it. The diagonal terms \(i = j\) contribute \(K(0)/(nh)\), which explodes as \(h \to 0\). The remedy is to leave the \(i\)-th observation out:
and \(\hat h_{\text{CV}} = \arg\min_h \operatorname{CV}(h)\). One can show that \(\mathbb{E}\,\operatorname{CV}(h) = \operatorname{MISE}(h) - \int f^2\): up to a constant, \(\operatorname{CV}(h)\) is an unbiased estimator of the MISE.
For the Gaussian kernel, \(K * K\) is the \(N(0, 2)\) density, so everything is explicit. For other kernels, \(K * K\) can be computed once, or \(\int \hat f_h^2\) can be integrated numerically.
Example
We compare both rules on a bimodal mixture, \(\tfrac12 N(-2, 1) + \tfrac12 N(2, 1)\), with \(n = 400\). bw.nrd implements the normal reference rule above and bw.ucv implements least-squares cross-validation.
Figure 1: Kernel density estimates of a bimodal mixture with two bandwidth rules, against the true density.
The normal reference rule treats the two modes as a single wide normal, so its bandwidth is too large: it flattens both peaks and partly fills in the valley, and its ISE is 2.7 times that of cross-validation. Cross-validation adapts to the shape and gives a smaller bandwidth. Its price is variability: \(\hat h_{\text{CV}}\) changes noticeably from sample to sample, which is a well-known weakness of least-squares cross-validation.