advanced37 min studyLesson 712 in Mathematics

Kernel density estimation and bandwidth

Normalize a density smoother, derive its leading bias and variance, and separate interior asymptotics from boundary behavior.

On this page

What you’ll understand

  • Calculate a normalized kernel density estimate.
  • Explain the leading bandwidth bias and variance orders.
  • Recognize boundary bias and the limits of an asymptotic bandwidth formula.

A cumulative distribution can be estimated without smoothness, but estimating its density asks how probability mass changes over very short distances. Kernel smoothing spreads each observation into a small normalized bump. The bandwidth controls both the spatial resolution and the amount of random fluctuation. Narrow bumps resolve more detail while using fewer effective observations near a point. The resulting tradeoff is mathematical, not simply aesthetic, and its familiar formulas need hypotheses about the density, kernel, and location being considered.

Every observation contributes a normalized bump

For an iid sample from a Lebesgue density f on the real line, choose an integrable kernel K with integral one and bandwidth h>0. The estimate averages h−1K((x−Xi)/h)h^{-1}K((x-X_i)/h). If K is nonnegative, the estimate is nonnegative and integrates to one. The factor h inverse is essential: widening a bump lowers its height while preserving its probability mass. A symmetric kernel has zero first moment when that moment is finite, but symmetry alone does not supply finite second moments or square integrability.

The expectation of the estimate is the convolution of f with the rescaled kernel, so smoothing creates bias before sampling variability enters. A signed higher-order kernel can cancel additional moments and reduce certain bias terms, but its estimate can be negative. Thus unit integral and nonnegativity are distinct requirements. Calling every finite curve a density because it has a plausible shape overlooks both normalization and support. A density value also has inverse measurement units; changing the units of the observations must change its numerical height.

f^h(x)=1nh∑i=1nK ⁣(x−Xih),Eff^h(x)=(Kh∗f)(x),Kh(u)=h−1K(u/h)\widehat f_h(x)=\frac1{nh}\sum_{i=1}^nK\!\left(\frac{x-X_i}{h}\right),\qquad \mathbb E_f\widehat f_h(x)=(K_h*f)(x),\quad K_h(u)=h^{-1}K(u/h)
The displayed construction has unit integral; nonnegativity additionally requires a nonnegative kernel.↔ Scroll wide equations horizontally.

Leading orders explain bandwidth sensitivity

Take a bounded, nonnegative, symmetric, compactly supported kernel with integral one, positive second moment μ2(K)\mu_2(K), and R(K)=∫K2R(K)=\int K^2. At a fixed point where f is twice continuously differentiable in a neighborhood, Taylor expansion gives bias h2μ2(K)f′′(x)/2+o(h2)h^2\mu_2(K)f''(x)/2+o(h^2). With f continuous there, h tending to zero and nh tending to infinity, the variance is f(x)R(K)/(nh)+o((nh)−1)f(x)R(K)/(nh)+o((nh)^{-1}). These are asymptotic expansions, not exact finite-sample errors for every density.

For a density f in W²,²(R), the Sobolev space with two square-integrable weak derivatives, and the same compactly supported kernel, the leading mean integrated squared error balances a term proportional to h to the fourth power against a term proportional to one over nh. The optimizing order is n to the minus one-fifth in one dimension. Its constant depends on the unknown curvature of f, so the expression is an oracle guide rather than an implementable instruction by itself. Cross-validation and plug-in rules estimate different ingredients and can behave differently on finite samples.

AMISE⁡(h)=μ2(K)2R(f′′)4h4+R(K)nh,hAMISE=[R(K)nμ2(K)2R(f′′)]1/5\operatorname{AMISE}(h)=\frac{\mu_2(K)^2R(f'')}{4}h^4+\frac{R(K)}{nh},\qquad h_{\mathrm{AMISE}}=\left[\frac{R(K)}{n\mu_2(K)^2R(f'')}\right]^{1/5}
This approximation assumes the stated regularity, positive curvature integral, and an interior or whole-line setting without an uncorrected support boundary.↔ Scroll wide equations horizontally.

Boundaries change the approximation problem

If a density is supported on a half-line and has a positive boundary value, a symmetric kernel spills mass outside the support. At the boundary its expectation may approach half the correct height rather than the height itself. The interior Taylor calculation cannot be used across a discontinuity in the density's zero extension. Reflection, boundary kernels, transformations, or local-polynomial density methods address particular boundary settings; none is justified merely by shrinking the bandwidth while retaining the same incorrect boundary argument.

Bandwidth controls a spatial scale, whereas increasing the sample size supplies more information at that scale. Comparing estimates at several bandwidths can reveal instability but does not distinguish noise from a genuine narrow feature without assumptions. Multivariate product kernels also pay a variance cost involving the product of bandwidths, which becomes severe as dimension grows. The normalization, effective local sample size, and applicable smoothness class should be stated before declaring a visually detailed estimate more accurate than a smooth one.

A wider window need not lower a particular height

Use data 0,1,2,3 and the box kernel K(u)=1/2 for |u|≤1. Compute the density estimate at x=1 for bandwidths 0.75 and 1.25.

  1. With h=0.75, only the observation at one is within the kernel window. Its kernel value is one-half, so the estimate is (1/2)/(4×0.75)=1/6.

  2. With h=1.25, observations zero, one and two are inside the window while three is outside. The estimate is (3/2)/(4×1.25)=0.3. None of these distances lies exactly on a window boundary.

  3. Every individual bump is shorter at the larger bandwidth, but more bumps contribute at this location. The total height increases here while the complete estimate remains normalized at both bandwidths. A pointwise increase does not contradict the overall smoothing effect.

The result

The heights are 1/6 and 0.3. Bandwidth changes overlap and normalization together, not merely vertical scale.

Explore the model

Interactive lab

Interactive lab · heat

Smoothing suppresses finer spatial oscillations

Pause and Reset, then set both controls to spatial mode n=1 and diffusivity κ=0.5. Take two Steps to time 1; predict amplitude exp(−0.5), about 0.606531. Reset, set n=2 and κ=0.5, and take two Steps; predict exp(−2), about 0.135335. Heat flow is an exact deterministic smoothing analogy. It does not fit a density, choose a bandwidth, or display sampling variance.

Smoothing suppresses finer spatial oscillationsThe exact periodic heat-equation mode is u(x,t) = exp(−κn²t) sin(nx), on [0,2π]. Playback advances physical time. The initial sine is shown separately, and the unnormalized L² norm is √π exp(−κn²t). This analytic instrument does not run a finite-difference solver or test discretization stability. Current readings: Current amplitude: 1; Spatial L² norm: 1.772; Decay rate · κn²: 3.6 /s. All parameters are adjustable with the labeled controls below.Periodic heat equation mode 3 at time 0: the amplitude is 1.0π/2π3π/22π−1−0.500.51x · periodic intervalTemperature perturbation uExact mode · n = 3
Current temperature modeInitial sineCurrent amplitude
Current amplitude
1
Spatial L² norm
1.772
Decay rate · κn²
3.6 /s
t = 0 s

The exact periodic heat-equation mode is u(x,t) = exp(−κn²t) sin(nx), on [0,2π]. Playback advances physical time. The initial sine is shown separately, and the unnormalized L² norm is √π exp(−κn²t). This analytic instrument does not run a finite-difference solver or test discretization stability. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.

Look forA smoothing operator can attenuate fine spatial structure faster than coarse structure.

Check your understanding

For a conventional second-order kernel in the stated interior regime, what happens to leading bias and variance when h is halved at fixed n?

Try it yourself

For the Epanechnikov kernel K(u)=3(1−u²)/4 on [−1,1], calculate its second moment and squared integral. State why these two constants enter different parts of the leading risk.

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

Expand the even polynomials and integrate from zero to one, then double the result.

Compare with the solution

The second moment is (3/2)(1/3−1/5)=1/5. The squared integral is (9/8)(1−2/3+1/5)=3/5. The second moment multiplies the density curvature in the bias, so its square enters squared bias. The squared integral instead controls the leading variance of the localized random bump. Their roles cannot be exchanged even though both are kernel-dependent constants.

Take it with you

  • Bandwidth rescales bump height and width while preserving mass.
  • Interior second-order smoothing balances squared bias h⁴ against variance 1/(nh).
  • Boundary corrections and signed kernels require separate qualifications.

Read further

Original sources and deeper explanations to follow at your own pace.

Optional progress, saved in this browser when available. Revisit any lesson at any time.

Lesson not marked complete.