Kernel Density Estimation and Distribution Testing (KDE)

Statistics
Introduced by
Rosenblatt (1956); Parzen (1962); textbook treatment by Silverman
Year
1956
Type
Nonparametric density estimation

What does it do?

Kernel Density Estimation (KDE) is a nonparametric method that estimates a continuous probability density by placing a smooth kernel function over each observation, without assuming a parametric distribution.

It traces back to Rosenblatt (1956) and was treated at textbook length by Silverman (1986). KDE is a density estimation and visual comparison method: it shows and contrasts the shapes of estimated densities, but it does not by itself provide a formal test with a test statistic, null hypothesis and p-value. For formal distribution tests, see the Anderson-Darling and Lilliefors pages.

The intuition behind the method

Imagine dropping a small, smooth bump centred on every data point and then adding all the bumps together. Where observations cluster, the bumps overlap and pile up into a tall ridge; where data are sparse, the curve stays low. The result is a smooth picture of where the data are dense, free of the jagged, bin-edge artefacts of a histogram.

History

Kernel density estimation originates with Rosenblatt's 1956 note on nonparametric estimates of a density function, which showed that estimates of this type are biased under mild conditions. Silverman's 1986 monograph gave a systematic textbook treatment of the method, including the bandwidth rule that bears his name.

When to use it

Use KDE when you have continuous data and want to see the shape of a distribution, or to compare shapes across samples, without committing to a parametric model such as the normal. As a rough informal guide, samples of about 30 observations or more give a more stable estimate; with fewer observations the curve depends strongly on the bandwidth choice, and a histogram or simple descriptive statistics may be more transparent. Do not use it for discrete or strictly categorical data. Because the bandwidth strongly affects the result, start from an automatic rule such as Silverman's or cross-validation, check the curve across a few bandwidths, and prefer a data-driven selector when the data may be multimodal or strongly skewed.

Limitations and considerations

  • The result depends heavily on the bandwidth h, which sets how far each kernel spreads its contribution; the Silverman rule ties h to n, the standard deviation, and the IQR.
  • Rosenblatt's 1956 note showed that all density estimates satisfying relatively mild conditions are biased, so the estimate is an approximation whose error must be considered.
  • With small samples the estimate is highly sensitive to the bandwidth, and a histogram is often a simpler and more transparent alternative.
  • With very few observations, simple descriptive statistics are generally more informative than a density curve.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • Makes no parametric distribution assumption, so it can show skewness, multiple modes, and heavy tails that a fitted normal curve would hide.
  • Produces a smooth, continuous density estimate, avoiding the bin-edge dependence of a histogram.
  • Densities estimated from two samples can be plotted on the same axes, giving a direct visual comparison of their shapes.

Applications

  • Visualising the shape of a continuous variable to check for skewness, multiple modes, or heavy tails.
  • Comparing the distributions of two or more samples visually, without assuming normality.
  • Exploratory data analysis as a smoother alternative to the histogram.

How it works

How it works

1

The density estimate at a point x is the average of kernel functions K centred on each observation x_i, scaled by the bandwidth h. Each observation contributes a small smooth bump, and summing these bumps gives a continuous estimate of the underlying density. Because the bumps are averaged over n observations, the estimate integrates to one when K is itself a density. A common default for K is the Gaussian kernel, a symmetric bell-shaped density. The choice of kernel usually has a smaller effect on the estimate than the choice of bandwidth.

Formula
\hat{f}_h(x) = \frac{1}{n h}\sum_{i=1}^{n} K\!\left(\frac{x - x_i}{h}\right)
2

The bandwidth h controls how wide each bump is and therefore how smooth the estimate becomes. The Silverman rule shown here sets h from the sample size n, the sample standard deviation, and the interquartile range (IQR), so the bandwidth shrinks as n grows. The rule is derived for a roughly normal reference shape, so it can oversmooth data with several modes or strong skew. Sheather-Jones and cross-validation select the bandwidth from the data itself rather than from a normal reference, and they are common alternatives in those cases.

Formula
h_{\text{Silverman}} = 0.9\, \min\!\left(\hat{\sigma},\, \frac{\text{IQR}}{1.34}\right) n^{-1/5}

Common pitfalls

  • Reading structure into the curve when the bandwidth is too small (spurious bumps) or too large (real modes smoothed away). Compare the curve across several bandwidths before interpreting it.
  • Applying KDE to very small samples, where the estimate is dominated by the bandwidth choice rather than the data. Treat curves from small samples as tentative and check them across several bandwidths.
  • Ignoring natural boundaries. A standard kernel smooths beyond them and places density in impossible regions, for example below zero for a strictly positive quantity.
  • Interpreting the default kernel and bandwidth as the true shape of the data rather than as modelling choices that shape the curve.

Frequently asked questions

How is KDE different from a histogram?

A histogram counts observations into fixed bins, producing a step function whose appearance depends on bin edges and widths. KDE instead places a smooth kernel on each observation and sums them, giving a continuous curve free of bin-edge artefacts, though it still depends on the bandwidth.

What is the bandwidth and how do I choose it?

The bandwidth h sets how wide each kernel bump is and therefore how smooth the estimate is. Too small a bandwidth produces a spiky, noisy curve; too large oversmooths and hides real features. Silverman's rule gives a quick automatic choice based on a roughly normal reference shape, so it can oversmooth multimodal data. Sheather-Jones and cross-validation select the bandwidth from the data itself and are common alternatives.

Does KDE require the data to be normal?

No. KDE is nonparametric and makes no parametric distribution assumption. It requires continuous data, and it is useful precisely for revealing non-normal shapes such as skewness or multimodality.

How much data do I need?

As a rough informal guide, about 30 observations or more gives a more stable estimate. With small samples the curve is dominated by the bandwidth choice, so a histogram or simple descriptive statistics may be more transparent. Check any curve across several bandwidths before drawing conclusions.

Related methods

Sources

  1. Rosenblatt, M. (1956). Remarks on Some Nonparametric Estimates of a Density Function. Annals of Mathematical Statistics, 27(3), 832-837.

    Open DOI reference
  2. Silverman, B. W. (1986). Density Estimation for Statistics and Data Analysis. Chapman & Hall / CRC Press.

    ISBN: 978-0412246203